猪条件算子

时间:2013-06-07 02:11:52

标签: apache-pig

考虑以下关系

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

有没有办法实现以下

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

1 个答案:

答案 0 :(得分:11)

您可以执行FOREACH并使用三元运算符,如下所示。

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