我们说我有一些表f,包括以下列:
a, b
0, 1
0, 0
0, 0
0, 1
1, 0
1, 1
我想创建一个等于a的新列c湾
我尝试过以下方法:
f = foreach f generate a, b, ((a or b) == 1) ? 1 : 0 as c;
但收到以下错误:
ERROR org.apache.pig.tools.grunt.Grunt - ERROR 1200: Pig script failed to parse: NoViableAltException(91@[])
答案 0 :(得分:2)
OR
条件构造不正确,你能试试吗?
f = foreach f generate a, b, (((a==1) or (b==1))?1:0) AS c;
示例示例:
的输入强>
0,1
0,0
0,0
0,1
1,0
1,1
<强> PigScript:强>
A = LOAD 'input' USING PigStorage(',') AS (a:int,b:int);
B = foreach A generate a, b, (((a==1) or (b==1))?1:0) AS c;
DUMP B;
<强>输出:强>
(0,1,1)
(0,0,0)
(0,0,0)
(0,1,1)
(1,0,1)
(1,1,1)