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 >> Counting tuple elements


Copy link to this message
-
Re: Counting tuple elements
Yes, see GROUP and COUNT. Something like this:

fruits = LOAD '/my/fruit' AS (name:chararray);
grouped = GROUP fruits BY name;
counts = FOREACH grouped GENERATE group, COUNT(fruits);
DUMP counts;

On Fri, May 4, 2012 at 9:06 AM, James Newhaven <[EMAIL PROTECTED]>wrote:

> Say I have a tuple containing the following elements (Apples, Apples,
> Oranges, Carrots, Carrots)
>
> Is it possible in pig to find the counts of the tuple, for example the
> output I would like is:
>
> (Apples, 2)
> (Oranges, 1)
> (Carrots, 2)
>
> Thanks,
> James
>

--
*Note that I'm no longer using my Yahoo! email address. Please email me at
[EMAIL PROTECTED] going forward.*
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