You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@pig.apache.org by James Newhaven <ja...@gmail.com> on 2012/05/29 00:40:43 UTC

Summing the contents of a bag

Given a relation that contains this:

({(11),(9)})
({(8),(7)})

Is it possible for me to SUM the contents of each bag so I get:
(20)
(15)

Thanks,
James

Re: Summing the contents of a bag

Posted by Abhinav Neelam <ab...@gmail.com>.
Sorry if I've misunderstood the question but isn't this exactly what the
builtin function SUM does?
Given that your relation is contained in the alias 'in' and has this schema:
grunt> describe in;
in: {bagdata: {(int)}}

you could do this:
grunt> out = foreach in generate SUM(bagdata);
grunt> dump out;
(20)
(15)


On 29 May 2012 04:10, James Newhaven <ja...@gmail.com> wrote:

> Given a relation that contains this:
>
> ({(11),(9)})
> ({(8),(7)})
>
> Is it possible for me to SUM the contents of each bag so I get:
> (20)
> (15)
>
> Thanks,
> James
>



-- 
Hacking is, and always has been, the Holy
Grail of computer science.