You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@pig.apache.org by Shin Chan <ha...@gmx.com> on 2012/04/15 07:44:09 UTC

Sum and count of fields

Hi

 I have data something like

 f1,f2,f3,f4,f5

 Rows with 5 fields

 I have to produce final dump output as

 f1,f2,f3, SUM( all fields at f4 position) , COUNT ( number of fields at f5 position ) , f4 , f5

 I am trying to do using group , foreach , flatten but its getting confusing. Since flatten produce cross product i am getting lots of rows.
 My final output should have same number of rows as input but with SUM , COUNT columns added.

Thanks in advance for your help

Re: Sum and count of fields

Posted by Prashant Kommireddi <pr...@gmail.com>.
You mean count of distinct elements at f5?

Sent from my iPhone

On Apr 14, 2012, at 10:44 PM, Shin Chan <ha...@gmx.com> wrote:

> Hi
>
> I have data something like
>
> f1,f2,f3,f4,f5
>
> Rows with 5 fields
>
> I have to produce final dump output as
>
> f1,f2,f3, SUM( all fields at f4 position) , COUNT ( number of fields at f5 position ) , f4 , f5
>
> I am trying to do using group , foreach , flatten but its getting confusing. Since flatten produce cross product i am getting lots of rows.
> My final output should have same number of rows as input but with SUM , COUNT columns added.
>
> Thanks in advance for your help