Reputation: 11
I have a file like - (1950,10) (1951,33) (1952,15) (1953,17) (1954,17) (1955,14) (1956,60) (1957,98) (1958,73) (1959,87) (1960,123)
I want to get the sum of the second field through Pig. eg out put should be like (547)
Please help
Upvotes: 1
Views: 77
Reputation: 3261
You can do like this. You have to group all your records..
x = LOAD '/root/stack.txt' USING PigStorage(',') as (year:int,score:int);
y = GROUP x ALL;
z = FOREACH y GENERATE SUM(x.score);
dump z;
Answer:
(547)
Is that solves your problem......
Upvotes: 1