user182944
user182944

Reputation: 8067

Pig: Invalid field Projection; Projected Field does not exist

describe filter_records;

This gives me the below format:

filter_records: {details1: (firstname: chararray,lastname: chararray,age: int,gender: chararray),details2: (firstname: chararray,lastname: chararray,age: int,gender: chararray)}

I want to display the firstname from both details1 and details2. I tried this:

display_records = FOREACH filter_records GENERATE display1.firstname;

But I am getting the error:

Invalid field projection. Projected field [display1] does not exist in schema: details1:tuple(firstname:chararray,lastname:chararray,age:int,gender:chararray),details2:tuple(firstname:chararray,lastname:chararray,age:int,gender:chararray).

Please suggest why this error and how to resolve this.

Upvotes: 4

Views: 10263

Answers (1)

Sivasakthi Jayaraman
Sivasakthi Jayaraman

Reputation: 4724

I didn't see any relation name display1 in the filter_records. I guess instead of details1.firstname you used display1.firstname. Can you change your script like this?

display_records = FOREACH filter_records GENERATE details1.firstname;

It seems you used same variable names(firstname, lastname,age,gender) in both details1 and details2. It will give duplicate error when you print like this

display_records = FOREACH filter_records GENERATE details1.firstname,details2.firstname;

To solve this issue you need to provide a unique names in the details1 and details2 relation, Can you change your load schema like this? or you can give any unique name in the details1 and details2.

details1:tuple(firstname1:chararray,lastname1:chararray,age1:int,sex1:chararray),details2:tuple(firstname2:chararray,lastname2:chararray,age2:int,sex2:chararray)

Now when you try like this, you will get the firstname from details1 and details2

display_records = FOREACH filter_records GENERATE details1.firstname1,details2.firstname2;

Upvotes: 4

Related Questions