猪条件算子

rah*_*hul 9 apache-pig

考虑以下关系

test = LOAD 'input' USING PigStorage(',') as (a:chararray, b:chararray);
Run Code Online (Sandbox Code Playgroud)

有没有办法实现以下目标

if (b == 1) {
    a = 'abc';
else if (b == 2) {
    a = 'xyz';
else 
    // retain whatever is there in the column 'a'
Run Code Online (Sandbox Code Playgroud)

Fre*_*ric 11

您可以FOREACH按如下方式执行并使用三元运算符.

test2 = FOREACH test GENERATE (b=='1' ? 'abc' : (b=='2' ? 'xyz' : a)) AS a, b;
Run Code Online (Sandbox Code Playgroud)