pig过滤器或运算符

sbdsn5lh  于 2021-06-21  发布在  Pig
关注(0)|答案(1)|浏览(652)
a = load '/user/home/samp.txt' using PigStorage(',');
dump a;
(2008-Jan-12,12.1,13.1,36.0)
(2008-Jan-13,13.1,14.1,45.00)
(2008-Jan-15,14.2,15.2,47.00)
(2008-Jan-16,16.1,17.1,47.5)
(2008-Jan-12,8.5,17,50,12.0)
(2008-Jan-12,n#/a,n#/a,n#/a)
(2008-Jan-19,n#/a,n#/a,n#/a)
(2008-Jan-12,n#/a,n#/a,27)
(2008-Jan-12,n#/a,13.00,n#/a)
b = filter a by ($1!='n#/a' OR $2!='n#/a' OR $3!='n#/a');
dump b;
(2008-Jan-12,12.1,13.1,36.0)
(2008-Jan-13,13.1,14.1,45.00)
(2008-Jan-15,14.2,15.2,47.00)
(2008-Jan-16,16.1,17.1,47.5)
(2008-Jan-12,8.5,17,50,12.0)
(2008-Jan-12,n#/a,n#/a,27)
(2008-Jan-12,n#/a,13.00,n#/a)

为什么我还是要 "n#/a" 在b中

bnl4lu3b

bnl4lu3b1#

结果与预期一致,因为您正在使用!=和或。你和我吵架了 "n#/a" 因为至少有一个条件对 (2008-Jan-12,n#/a,n#/a,27) 以及 (2008-Jan-12,n#/a,13.00,n#/a) 如果要筛选没有 "n#/a" 使用 AND .

B = FILTER A BY (($1 != 'n#/a') AND ($2 != 'n#/a' ) AND ($3 != 'n#/a' ));

如果要使用或,则组合逻辑或结果,然后取反

B = FILTER A BY NOT($1 == 'n#/a' OR $2 == 'n#/a' OR $3 == 'n#/a');

B = FILTER A BY NOT($1 matches 'n#/a' OR $2 matches 'n#/a' OR $3 matches 'n#/a');

输出

相关问题