Search code examples
apache-pighue

how do you do sql count in pig , count(var2 ) group by var1 ?


so I have pig script below .. here I am able to group by var1 , then concatenate var2 values into one line by var1 , how can I do something similar to var1, count(var2 ) group by var1

data = load 'inputP2' using textloader as (var1:int, var2:int);
result = group data by var1;
store result into 'outputP2';

Solution

  • You need to use COUNT function to get the result. Can you try this?

    cnt = FOREACH result GENERATE group,COUNT(data.var2);
    store cnt into 'outputP3';
    

    Reference: http://pig.apache.org/docs/r0.13.0/func.html#count