Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/278.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中使用聚合函数_Apache Pig - Fatal编程技术网

Apache pig 在Pig中使用聚合函数

Apache pig 在Pig中使用聚合函数,apache-pig,Apache Pig,我的输入文件在下面 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

我的输入文件在下面

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
我需要输出如下


这里有一个可能的解决方案

您可以这样做(未经测试):

这应该可以做到

试试这个

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';

搜索
过滤器
计数
。这会引导你找到你的答案。我调整了我的输入文件,在每个元组的中间引入了一个新的atom。你现在能帮我跟进GoBrewers14的评论吗?同时也可以查找嵌套的
FOREACH
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';