Uno
Uno

Reputation: 543

Accessing fields of Tuples

I have the following pig Script:
My file 1.txt has A 1
B 2
C 3
D 4

grunt> A = load '1.txt' using PigStorage(' ') as (a:chararray,b:int);  
grunt> B = foreach A generate A.a;  
grunt> dump B;

It gives me the following error

ERROR org.apache.pig.tools.grunt.Grunt - ERROR 2997: Unable to recreate exception from backed error: org.apache.pig.backend.executionengine.ExecException: ERROR 0: Scalar has more than one row in the output. 1st : (A,1), 2nd :(B,2)

Upvotes: 3

Views: 3749

Answers (1)

Donald Miner
Donald Miner

Reputation: 39943

You don't have to reference a as A.a. Try this instead:

grunt> A = load '1.txt' using PigStorage(' ') as (a:chararray,b:int);  
grunt> B = foreach A generate a;  
grunt> dump B;

C.x is for grabbing a "column" out of a bag. Say C is a bag of items, then C.x will create a new bag of all of the x's in that bag. That's not what you want here. The foreach is iterating through the bag here for you.

Upvotes: 6

Related Questions