使用 Pig 条件运算符来实现或? [英] Using Pig conditional operator to implement or?
本文介绍了使用 Pig 条件运算符来实现或?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有一个表 f,由以下列组成:
Let's say I have some table f, consisting of the following columns:
a, b
0, 1
0, 0
0, 0
0, 1
1, 0
1, 1
我想创建一个新列 c,它等于 a |湾
I want to create a new column, c, that is equal to 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@[])
推荐答案
OR
条件构造不正确,可以试试这个吗?
The OR
condition construction is not correct, Can you try this?
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)
这篇关于使用 Pig 条件运算符来实现或?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文