Home Forums Pig SAMPLE nested in FOREACH

This topic contains 1 reply, has 1 voice, and was last updated by  Andy Kruth 11 months, 1 week ago.

  • Creator
    Topic
  • #45709

    Andy Kruth
    Member

    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.

Viewing 1 replies (of 1 total)

You must be logged in to reply to this topic.

  • Author
    Replies
  • #45713

    Andy Kruth
    Member

    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!

    Collapse
Viewing 1 replies (of 1 total)