找到最大数量的基础上,城市和产品使用Pig?

yvt65v4c  于 2021-06-24  发布在  Pig
关注(0)|答案(1)|浏览(239)

我必须找出在城市和产品上的最大花费。
我的实现:

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)

预期产量

(Com ports,Reno,279)
(Exer & Fit,clark,2000)
(Wat ports,colum,500)
(Team Sports,Petersburg,421)
(Recreation,charleston,1974)
(Exer & Fit,long beach,300)

请帮帮我。。

bxgwgixi

bxgwgixi1#

按产品和城市分组。

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

相关问题