我的输入文件在
下面a1,1,on,400
a1,2,off,100
a1,3,on,200
只有当$ 2等于" on"我才需要添加3美元。我已经编写了如下脚本,之后我不知道如何继续。仅添加3美元我需要应用一些过滤器。添加$ 1,根本没有过滤器
有人可以帮我完成这件事。
myinput = LOAD 'file' USING PigStorage(',') AS(id:chararray,flag:chararray,amt:int)
grouped = GROUP myinput BY id
我需要输出如下
a1,6,600
答案 0 :(得分:1)
这是一个可能的解决方案,
你可以这样做(未经测试):
myinput = LOAD 'file' USING PigStorage(',');
A = FOREACH myinput GENERATE $0 as id, $1 as first_sum, (($2 == 'on') ? $3 : 0) as second_sum;
grouped = GROUP A BY id;
RESULT = FOREACH grouped GENERATE group as id, SUM($1.first_sum), SUM($1.second_sum);
应该做的伎俩
答案 1 :(得分:0)
尝试一下
myinput = LOAD '/home/gopalkrishna/PIGPRAC/pig-sum.txt' using PigStorage(',') as (name:chararray,num:int,stat:chararray,amt:int);
A = GROUP myinput BY name;
B = FOREACH A GENERATE group, SUM(myinput.num),SUM(myinput.amt);
STORE B INTO 'SUMOUT';