You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@pig.apache.org by paradisehit <pa...@163.com> on 2008/09/02 11:44:45 UTC
How to ORDER like my example?
I use GROUP can manage the data that has the same "value" into one bag.
For example:
character, num
(b, 1) (a, 1)
(b, 2) group (a, {(a, 2)})
{(a, 1)} => { (a, 1) }
(a, 2) (b, {(b, 1)})
(a, 1) (b, 2)
But now I wanna the result is orderd by the num, and also the same character is together.
just like this result:
(b, 1)
(b, 2)
(a, 1)
(a, 1)
(a, 2)
and the alpha order is not changed.
How? Can someone help me?
Re: How to ORDER like my example?
Posted by Alan Gates <ga...@yahoo-inc.com>.
I'm not clear if you want to order inside your groups, or you want to
order after you group, using both the grouping key and additional keys.
If you want to order inside your groups, you can do the following:
A = load 'myfile';
B = group A by $0;
C = foreach B {
C1 = order A by $1;
generate C1;
}
dump C;
This will dump each group, with the contents of the group ordered by the
second field. However, there is no guarantee the groups themselves in be
in any particular order. If you wish to order on both the grouping key
and additional fields, your script would look like:
A = load 'myfile';
B = group A by $0;
C = foreach B generate flatten(A);
D = order C by ($0, $1);
dump D;
Alan.
paradisehit wrote:
>
> I use GROUP can manage the data that has the same "value" into one bag.
> For example:
> character, num
> (b, 1) (a, 1)
> (b, 2) group (a, {(a, 2)})
> {(a, 1)} => { (a, 1) }
> (a, 2) (b, {(b, 1)})
> (a, 1) (b, 2)
> But now I wanna the result is orderd by the num, and also the same character is together.
>
> just like this result:
> (b, 1)
>
> (b, 2)
> (a, 1)
> (a, 1)
> (a, 2)
>
> and the alpha order is not changed.
>
> How? Can someone help me?
>
>