Pig - ERROR 1045: AVG as multiple or none of them fits. Please use explicit cast

I have a comma separated .txt file, I want the DUMPage of AVGall Males.

records = LOAD 'file:/home/gautamshaw/Documents/PigDemo_CommaSep.txt' USING PigStorage(',') AS (firstname:chararray,lastname:chararray,age:int,sex:chararray);
filter_by_male = FILTER records BY sex == 'M';
grouped = GROUP filter_by_male ALL;
average_male_age = FOREACH grouped GENERATE AVG(records.age);

I get an error in the line FOREACH:

ERROR org.apache.pig.tools.grunt.Grunt - ERROR 1045: 
<line 6, column 44> Could not infer the matching function for org.apache.pig.builtin.AVG as multiple or none of them fit. Please use an explicit cast.

Please advice.

+4
source share
1 answer

You do not have to design a relationship records, it should be a relationship filter_by_male.

Can you change your script as follows?

average_male_age = FOREACH grouped GENERATE AVG(filter_by_male.age);
+5
source

All Articles