我有一个逗号分隔.txt文件,我想DUMP
所有Males
的AVG
年龄。
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);
我在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.
请指教。
你不应该投射records
关系,它应该是filter_by_male
关系。
你能这样改变你的脚本吗?
average_male_age = FOREACH grouped GENERATE AVG(filter_by_male.age);