Search code examples
apache-pig

How to do sum of a column in Pig?


I have :

name | no
a 10
b 20
c 30

I want to sum no., that means I want x=60
how can I do that in PIG.


Solution

  • Considering you have your dataset in 'data' variable, here is the code:

    DESCRIBE data
    data: (name, no)
    
    data_grp = GROUP data ALL;
    result = FOREACH data_grp GENERATE SUM(data.no);