Reply
New Contributor
Posts: 1
Registered: ‎09-15-2017

Can some one help me to rectify the pig code

grunt>data = load 'newa.csv' using PigStorage(',') as (state:chararray,year:int,typecode:chararray,type:chararray,gender:chararray,age:chararray,total:int);

grunt>g = group data by gender;

grunt>s = foreach g generate group as gender, COUNT(total) as tot;//throws error below

 

<line 3, column 47> Invalid field projection. Projected field [total] does not exist in schema: group:chararray,data:bag{:tuple(state:chararray,year:int,typecode:chararray,type:chararray,gender:chararray,age:chararray,total:int)}.
Details at logfile: /home/cloudera/Desktop/pig_1505488402587.log

Posts: 375
Topics: 11
Kudos: 58
Solutions: 32
Registered: ‎09-02-2016

Re: Can some one help me to rectify the pig code

@Ekansh

 

Very recently I have started focusing on Pig for one of the task... Kind of beginner to pig :-), still the below points may help you

 

1. Since the issue shows the field total does not exists, dump the data and check the number of column in file and your column assignment are matching. If you have column name in newa.csv, remove all the column name

 

grunt> dump data;

 

2. Try the keyword in capital letter, the below two commands giving me two different output

 

grunt> s = foreach g generate group,count(data);

grunt> s = FOREACH g GENERATE group,COUNT(data);

 

Announcements