Search code examples
ubuntuhadoopapache-pigvirtualization

Error in pig command


I am working through some examples on a new hadoop/pig setup.
This, rather straightforward example code is baffling me..

A1 = load 'passwd' using PigStorage(':') as (f1:chararray,f2:chararray,f3:chararray,f4:chararray,f5:chararray,f6:chararray,f7:chararray);

G = group A1 by f7;

foreach G generate group, a.$2;

the last foreach on G is failing with the following error message -

[main] ERROR org.apache.pig.tools.grunt.Grunt - ERROR 1000: Error during parsing.
Encountered " <IDENTIFIER> "foreach "" at line 1, column 1.

Can someone pls be polite enough to point me what am i missing here ? or am i just being rusty here..


Solution

  • Can you change the last line like this.

    H = foreach G generate group, A1.$2;
    DUMP H;
    

    here A1.$2 means you are trying to access f3 column, other option is

    H = foreach G generate group, A1.f3;