This may be helpful in understanding what happens when you do a group-by:
http://squarecog.wordpress.com/2010/05/11/group-operator-in-apache-pig/

Also, are you sure TOP doesn't give you items in order? It's a bag, but the
implementation is such that flattening it should give you things in proper
order (I think -- haven't tried).

D

On Tue, Apr 26, 2011 at 9:54 AM, Alan Gates <ga...@yahoo-inc.com> wrote:

> A has changed.  A outside the foreach is a relation (all the records you
> loaded).  Inside the foreach A is a bag created by the group by.  So what
> this does is order the bag A by the second input, and then take the top 3
> records.  Actually, given that order by goes from least to greatest this
> will give the bottom 3 records.  You'll need to change it to 'srtd = order A
> by second desc;' to get the top 3.
>
> Alan.
>
>
> On Apr 26, 2011, at 9:36 AM, ugo jardonnet wrote:
>
>  2011/4/26 Alan Gates <ga...@yahoo-inc.com>
>>
>>  topResults = foreach D {
>>>      srtd = order A by second;
>>>      top3 = limit srtd 3;
>>>      generate flatten(top3);
>>> };
>>>
>>> Alan.
>>>
>>> Thank you Alan. It works perfectly.
>>>
>>
>> I realize I didn't really understood the mechanism behind foreach.
>> Reading this piece of code I would have expect each top3 to be the same.
>> I suppose A is filtered by D at the beginning of the loop ?
>>
>
>

Reply via email to