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

Switch to Threaded View
Pig >> mail # user >> Pig Conditionals (Do I have to use UDFs)?

Copy link to this message
Pig Conditionals (Do I have to use UDFs)?
I'd like to generate based on exclusive conditions (something like the
CASE statement in SQL). An example:

Say I have data that looks like:

(a, 1)
(a, 2)
(b, 2)
(c, 1)
(d, 3)
(d, 4)

And I want to just convert each of the numbers to their written forms to

(a, one)
(a, two)
(b, two)
(c, one)
(d, three)
(d, four)

Would I need to write a udf for that, or is there some simple way to do
it using cases? I know I can do a bunch of bidirectional generates one
on top of the other to achieve this, like:

FOREACH rel GENERATE $0, (($1==1) ? 'one' : (($1 == 2) ? 'two' : (($1 ==
3) ? 'three' : 'four')));

but that seems too messy. I'd appreciate any advice.