Friday, October 31, 2014

Sum in Pig

This is a simple PigScript i wrote to understand the concepts of pig.
Well here it goes

Today we will see how to do a simple sum operation in Pig.

Consider this as my input data
1
2
3
4
1
1
1
view raw input hosted with ❤ by GitHub
.

The first example - sum
The second example - group and sum

-- Plain Sum
B = group A All;
C = foreach B generate SUM($1);
dump C;
-- Group And Sum
A = load 'input' as (number:int);
B = group A by $0;
C = foreach B generate SUM($1);
dump C;
view raw Sum hosted with ❤ by GitHub

No comments:

Post a Comment