我有一个逗号分隔的 .txt 文件,我想DUMP
所有男性
的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);
关于hadoop - Pig - 错误 1045 : AVG as multiple or none of them fit. 请使用显式转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28227791/