Pig Conditional Operators
Asked Answered
U

1

10

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'
Upheaval answered 7/6, 2013 at 2:11 Comment(0)
N
12

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;
Nunnally answered 7/6, 2013 at 9:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.