Home Forums Hortonworks Sandbox Baseball tutorial

This topic contains 1 reply, has 2 voices, and was last updated by  Larry Liu 1 year, 7 months ago.

  • Creator
    Topic
  • #25089

    In Batting. csv, there are records of players playing for multiple teams in the same year and scoring runs. For example,

    Year player ID runs
    1893 parroto01 3
    1893 parroto01 5

    In the code given below, which line adds up the runs scored by a player in different teams in the same year?

    batting = load ‘Batting.csv’ using PigStorage(‘,’);
    runs = FOREACH batting GENERATE $0 as playerID, $1 as year, $8 as runs;
    grp_data = GROUP runs by (year);
    max_runs = FOREACH grp_data GENERATE group as grp,MAX(runs.runs) as max_runs;
    join_max_run = JOIN max_runs by ($0, max_runs), runs by (year,runs);
    join_data = FOREACH join_max_run GENERATE $0 as year, $2 as playerID, $1 as runs;
    dump join_data;

Viewing 1 replies (of 1 total)

You must be logged in to reply to this topic.

  • Author
    Replies
  • #25142

    Larry Liu
    Moderator

    Hi, Sudhir
    From my understanding, none of the lines is doing what you asked.

    I recommend you to use dump to understand what the script does. For example

    batting = load ‘Batting.csv’ using PigStorage(‘,’);
    dump batting;

    From the output, you will have a better understanding of the script.

    Thanks
    Larry

    Collapse
Viewing 1 replies (of 1 total)