Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache pig 使用Pig条件运算符实现or?_Apache Pig_Conditional Statements_Conditional Operator - Fatal编程技术网

Apache pig 使用Pig条件运算符实现or?

Apache pig 使用Pig条件运算符实现or?,apache-pig,conditional-statements,conditional-operator,Apache Pig,Conditional Statements,Conditional Operator,假设我有一些表f,由以下列组成: a, b 0, 1 0, 0 0, 0 0, 1 1, 0 1, 1 我想创建一个新的列c,它等于a | b 我尝试了以下方法: 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: NoViableAltExcept

假设我有一些表f,由以下列组成:

a, b
0, 1
0, 0
0, 0
0, 1
1, 0
1, 1
我想创建一个新的列c,它等于a | b

我尝试了以下方法:

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@[])

条件构造不正确,您能试试吗

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
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)
PigScript:

0,1
0,0
0,0
0,1
1,0
1,1
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)
输出:

0,1
0,0
0,0
0,1
1,0
1,1
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)