根据使用猪的城市和产品查找最大金额?

时间:2018-06-07 12:07:18

标签: apache-pig

我必须找出在城市上花费的最大金额以及产品。

我的实施:

listItems.clear();
listItems.addAll(newlist);

我得到了什么

A = LOAD '/home/cloudera/Desktop/test' USING PigStorage (',') AS (T_id:int,date:chararray,pro_id:int,amount:int,product:chararray,city:chararray);
B = FOREACH A GENERATE $3,$4,$5;
describe B;
B: {amount: int,product: chararray,city: chararray}
C = group B BY $2;
D = FOREACH C GENERATE group, MAX(B.amount);
DUMP D;

预期输出

(Reno,279)
(clark,2000)
(colum,500)
(Petersburg,421)
(charleston,1974)
(long beach,300)

请帮助我......

1 个答案:

答案 0 :(得分:0)

按产品和城市分组。

C = group B BY ($1,$2);
D = FOREACH C GENERATE FLATTEN(group) as (product,city), MAX(B.amount); 
DUMP D;