-
Notifications
You must be signed in to change notification settings - Fork 19
[pig] GROUP operator and MAX,SUM,AVG,COUNT
dsindex edited this page Jul 31, 2014
·
2 revisions
pig에서 특정 column에 한정해서 column(혹은 다른 column의)의 최대값을 얻고자 할 경우 GROUP BY
연산과 MAX()
함수를 사용할 수 있다.
...
F = STREAM E THROUGH proc AS (key:chararray, score:float, value:chararray);
-- get count of rows and max value in column 'score' for each 'key'
G = GROUP F BY key;
H = FOREACH G GENERATE FLATTEN(F.(key,score,value)), COUNT(F), MAX(F.score);
...
만약, 특정 column이 아니라 전체 rows를 대상으로 하는 경우는 아래와 같다.
...
F = STREAM E THROUGH proc AS (key:chararray, score:float, value:chararray);
-- get count of rows and max value in column 'score' through all rows
G = GROUP F ALL;
H = FOREACH G GENERATE FLATTEN(F.(key,score,value)), COUNT(F), MAX(F.score);
...