john aa
john aa
john aa
john bb
mary cc
mary cc
mary dd
代码:
A = LOAD 'file.dat' USING PigStorage(' ') as (name:chararray,score:chararray);
N = CUBE A BY CUBE(name,score);
N2 = FOREACH N GENERATE FLATTEN(group) AS (name,score), ((float)COUNT_STAR(cube)) As (totcnt:float);
N3 = FILTER N2 BY name!='null';
N4 = GROUP N3 BY name;
N5 = FOREACH N4 {
fil = order N3 BY score;
fil1 = LIMIT fil 1;
fil2 = FILTER N3 BY score!='null';
generate FLATTEN(fil2) AS (name:chararray,score:chararray,indcount:float),FLATTEN(fil1.totcnt) as (totcnt:float);
}
N6 = FOREACH N5 GENERATE name,score,(indcount/totcnt)*100;
DUMP N6;
1条答案
按热度按时间hgb9j2n61#
你能试试这个吗?
输入:file.dat
代码:
输出: