Apache pig 如何处理null+;猪的数字加法

Apache pig 如何处理null+;猪的数字加法,apache-pig,Apache Pig,我有一个数据模式,其中我有50+列。现在我有一个场景,需要将四个int列添加到一起。四分之一的人可能是空的 if i do null + 1 + null + 7 i get the result as null which is true as per given in the PIG https://pig.apache.org/docs/r0.7.0/piglatin_ref2.html#Nulls i.e. if either sub-expression is null, the

我有一个数据模式,其中我有50+列。现在我有一个场景,需要将四个int列添加到一起。四分之一的人可能是空的

if i do  null + 1 + null + 7 i get the result as null which is true as per given in the PIG 
https://pig.apache.org/docs/r0.7.0/piglatin_ref2.html#Nulls

i.e. if either sub-expression is null, the resulting expression is null.

有人能告诉我如何处理这种情况吗。我是否需要定义一个自定义项,或者只需要空值,然后执行添加操作就可以了。提前感谢

一个选项是,如果列值为空,则将列值设置为零,否则继续使用原始值。下面是一个示例

input.txt

1,,3
,5,6
7,8,
PigScript:

A = LOAD 'input.txt' USING PigStorage(',') AS (f1:int,f2:int,f3:int);
B = FOREACH A GENERATE ((f1 is null)?0:f1) + ((f2 is null)?0:f2) +((f3 is null)?0:f3);
DUMP B;
(4)
(11)
(15)
输出:

A = LOAD 'input.txt' USING PigStorage(',') AS (f1:int,f2:int,f3:int);
B = FOREACH A GENERATE ((f1 is null)?0:f1) + ((f2 is null)?0:f2) +((f3 is null)?0:f3);
DUMP B;
(4)
(11)
(15)