Hortonworks Sandbox Forum

Baseball tutorial

  • #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;

to create new topics or reply. | New User Registration

  • Author
  • #25142
    Larry Liu

    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.


You must be to reply to this topic. | Create Account

Support from the Experts

A HDP Support Subscription connects you experts with deep experience running Apache Hadoop in production, at-scale on the most demanding workloads.

Enterprise Support »

Become HDP Certified

Real world training designed by the core architects of Hadoop. Scenario-based training courses are available in-classroom or online from anywhere in the world

Training »

Hortonworks Data Platform
The Hortonworks Data Platform is a 100% open source distribution of Apache Hadoop that is truly enterprise grade having been built, tested and hardened with enterprise rigor.
Get started with Sandbox
Hortonworks Sandbox is a self-contained virtual machine with Apache Hadoop pre-configured alongside a set of hands-on, step-by-step Hadoop tutorials.
Modern Data Architecture
Tackle the challenges of big data. Hadoop integrates with existing EDW, RDBMS and MPP systems to deliver lower cost, higher capacity infrastructure.