Home | About | Sematext search-lucene.com search-hadoop.com
 Search Hadoop and all its subprojects:

Switch to Threaded View
Pig >> mail # user >> conditional and multiple generate inside foreach?

Copy link to this message
conditional and multiple generate inside foreach?
Possible to do conditional and more than one generate inside a foreach?

for example, I have tuples like this (names, days_ago)


b shows up 1 day ago, so it belongs to all of the following: yesterday, last
week, last month, and last quarter. So I'd like to turn the above to:


I imagine/dream I could do something like this

        if (days_ago <= 90) generate name,days_ago,'quarter';
        if (days_ago <= 30) generate name,days_ago,'month';
        if (days_ago <= 7)   generate name,days_ago,'week';
        if (days_ago == 1)   generate name,days_ago,'yesterday';
        if (days_ago == 0)   generate name,days_ago,'today';

of course that's not valid syntax. I could write my own UDF but would be
nice there's some way to get what I want without UDF.