Conditional pig operators

Consider the ratio below

test = LOAD 'input' USING PigStorage(',') as (a:chararray, b:chararray); 

Is there any way to achieve the following

 if (b == 1) { a = 'abc'; else if (b == 2) { a = 'xyz'; else // retain whatever is there in the column 'a' 
+8
apache-pig
source share
1 answer

You can do FOREACH and use the ternary operator as follows.

 test2 = FOREACH test GENERATE (b=='1' ? 'abc' : (b=='2' ? 'xyz' : a)) AS a, b; 
+11
source share

All Articles