Home | About | Sematext search-lucene.com search-hadoop.com
 Search Hadoop and all its subprojects:

Switch to Threaded View
Pig, mail # user - ordering tuple after grouping


Copy link to this message
-
Re: ordering tuple after grouping
Gianmarco De Francisci Mo... 2012-04-16, 20:43
Sure,
use a nested foreach.

grouped = group data by $0;
ordered = foreach grouped {
  sorted = order data by $1;
  first = limit sorted 1;
  generate first;
}

Beware, untested code.

Cheers,
--
Gianmarco

On Mon, Apr 16, 2012 at 22:31, Chan, Tim <[EMAIL PROTECTED]> wrote:

> Given data:
>
> (1, 55, abc)
> (2, 23, asd)
> (1, 85, xyz)
> (1, 2, aaa)
>
>
> I would like to group on $0 and then have my grouped tuple be ordered by
> $1. Is this possible?
>
> The output should look like this:
>
> (1, {(1, 2, aaa),(1,55,abc),(1,85,xyz)})
> (2, {(2,23,asd)})
>
>
> Then I would like to keep the first tuple for every group.
>
> For example:
>
> (1,2,aaa)
> (2,23,asd)
>
>
>