Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pig Conditional Operators

Tags:

apache-pig

Consider the below relation

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

Is there a 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'
like image 540
rahul Avatar asked Jun 07 '13 02:06

rahul


1 Answers

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

test2 = FOREACH test GENERATE (b=='1' ? 'abc' : (b=='2' ? 'xyz' : a)) AS a, b;
like image 194
Frederic Avatar answered Sep 28 '22 17:09

Frederic