Registrations Closing Soon for DevOps Certification Training by CloudxLab | Registrations Closing in

  Enroll Now

Pig - Calculate Average Dividend - Hands-on

Code

divs = LOAD '/data/NYSE_dividends' AS (exchange, stock_symbol, date, dividends);
grped = GROUP divs BY stock_symbol;
DUMP grped;
avged = FOREACH grped GENERATE  group,  AVG(divs.dividends);
STORE avged INTO 'avged';
cat avged/part-r-00000

Description

grunt> divs = LOAD '/data/NYSE_dividends' AS (exchange, stock_symbol, date, dividends);
grunt> describe divs
divs: {exchange: bytearray,stock_symbol: bytearray,date: bytearray,dividends: bytearray}
grunt>

After loading, divs basically represent a dataset in which each row is having two columns exchange and stock_symbol.

grunt> grped = GROUP divs BY stock_symbol;
grunt> describe grped;
grped: {group: bytearray,divs: {(exchange: bytearray,stock_symbol: bytearray,date: bytearray,dividends: bytearray)}}

grped contains rows where each row is having two columns/fields. first one is the group name and second is a list of divs.

grunt> avged = FOREACH grped GENERATE  group,  AVG(divs.dividends);
grunt> describe avgedavged: {group: bytearray,double}
grunt>

avged has some number of rows as grped just the values in the second column are aggregated using AVG function.


No hints are availble for this assesment

Answer is not availble for this assesment

Loading comments...