猪 - 错误1045:AVG多个或不适合.请使用明确的演员

use*_*944 6 hadoop mapreduce apache-pig bigdata

我有一个逗号分隔的.txt文件,我想DUMPAVG所有的年龄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);
Run Code Online (Sandbox Code Playgroud)

我收到错误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.
Run Code Online (Sandbox Code Playgroud)

请指教.

Siv*_*man 9

你不应该records建立它应该是filter_by_male关系的关系.

你能改变这样的剧本吗?

average_male_age = FOREACH grouped GENERATE AVG(filter_by_male.age);
Run Code Online (Sandbox Code Playgroud)