Detailed example of GROUP-BY
Tuesday, February 22, 2011
5:34 PM
grunt> junk = LOAD 'junk.dat' USING PigStorage('\t') AS (name, toys); 
grunt> DUMP junk;
(Alva,3)
(George,5)
(Fred,7)
(Alva,10)
(Alva,12)
grunt> stuff = GROUP junk BY name; 
grunt> DUMP stuff; 
(Alva,{(Alva,3),(Alva,10),(Alva,12)})
(Fred,{(Fred,7)})
(George,{(George,5)})
grunt> counts = FOREACH stuff GENERATE group, COUNT(junk); 
grunt> DUMP counts; 
…  Success!!
(Alva,3L)
(Fred,1L)
(George,1L)
grunt> sums = FOREACH stuff GENERATE group, SUM(junk.toys); 
grunt> DUMP sums; 
…  Success!!
(Alva,25.0)
(Fred,7.0)
(George,5.0)