Pig Forum

SAMPLE nested in FOREACH

  • #45709
    Andy Kruth
    Participant

    Hello,

    SAMPLE works great to get a small sample returned from a data relation, but does it work on grouped data inside of a FOREACH? Here is my script, my data is just a row file with field delimiters.

    This SAMPLE usage works just fine:

    data = load '/user/akruth/data.txt' using PigStorage('^') as (... Metro:chararray...);
    samples = sample data 0.1;
    dump samples;

    But say I want to do something like this:

    data = load '/user/akruth/data.txt' using PigStorage('^') as (... Metro:chararray... );
    grouped = group data by Metro;
    samples = foreach grouped {
    s = sample data 0.1;
    generate group as metro, s as sample;
    };

    I get this error: exception during parsing: Error during parsing. mismatched input ‘data’ expecting LEFT_PAREN
    The line number corresponds to this line: s = sample data 0.1;

    I think the culprit is the data structrue that is going in to SAMPLE but I don’t understand it well enough to fix it.

    Here are some describes:
    describe data;
    This works –> data: {…Metro:chararray…}

    describe grouped
    This doesn’t –> grouped: {group: chararray, data: {(…Metro:chararray…)}

    I think the key to the problem is the parentheses but I’m not sure what that means.

to create new topics or reply. | New User Registration

  • Author
    Replies
  • #45713
    Andy Kruth
    Participant

    Also, received this question from colleagues:

    “Why not just group AFTER doing the top level sampling.”

    My answer is that by doing that you are not guaranteed getting an even sample (or any sampling at all) for each possible Metro value.

    The use case here is to find all possible Metro values in the data set, then get an even sampling of data for each.

    Thanks!

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.