Lokesh

Apache Pig Nested ForEach Explaination

Discussion created by Lokesh on Jul 25, 2017
Latest reply on Jul 26, 2017 by Lokesh

Hi,

 

I am reading through basics of pig latin, i find it hard to understand how nested FOREACH..GENERATE work. 

 

Below is the pig script from the 'Programming Pig explaining nested foreach.

 

daily = load 'NYSE_dividends' as (exchange:chararray, symbol:chararray, date:chararray,dividends:float);

grpd = group divs by symbol;

top3 = foreach grpd {

sorted = order divs by dividends desc;

top = limit sorted 3;

generate group , flatten(top);

};

 

Can somebody please how this works? Will 'sorted' be replaced with bag of tuples for given symbol during each iteration?

 

Regards,

Lokesh

Outcomes