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 >> How do I flatten the first item in a bag after a group?


Copy link to this message
-
RE: How do I flatten the first item in a bag after a group?
Thanks Alan. In my use case this works for me.
________________________________________
From: Alan Gates [[EMAIL PROTECTED]]
Sent: Friday, February 10, 2012 2:38 PM
To: [EMAIL PROTECTED]
Subject: Re: How do I flatten the first item in a bag after a group?

first_tup = foreach x_grp {
        inner = limit $1 1;
        generate flatten(inner);
}

Note however that "first" has no real meaning here, as bags do not guarantee any order.  You're really just getting a random tuple from the bag.  You can order the bag by inserting an order statement inside the foreach before the limit.

Alan.

On Feb 10, 2012, at 2:28 PM, Chan, Tim wrote:

>
>
> x_grp = group x by $18;
>
> How do I output the first tuple in the bag generated by the group?
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