Home | About | Sematext search-lucene.com search-hadoop.com
NEW: Monitor These Apps!
elasticsearch, apache solr, apache hbase, hadoop, redis, casssandra, amazon cloudwatch, mysql, memcached, apache kafka, apache zookeeper, apache storm, ubuntu, centOS, red hat, debian, puppet labs, java, senseiDB
 Search Hadoop and all its subprojects:

Switch to Threaded View
Pig >> mail # user >> Summing the contents of a bag


Copy link to this message
-
Re: Summing the contents of a bag
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 <[EMAIL PROTECTED]> 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.
NEW: Monitor These Apps!
elasticsearch, apache solr, apache hbase, hadoop, redis, casssandra, amazon cloudwatch, mysql, memcached, apache kafka, apache zookeeper, apache storm, ubuntu, centOS, red hat, debian, puppet labs, java, senseiDB