apache pig中的sum:error 1045

1bqhqjot  于 2021-06-24  发布在  Pig
关注(0)|答案(1)|浏览(389)

我想用pig计算2和的除法

A = LOAD 's3://input' AS (filed1:chararray, filed2:int, field3:float, field4:float);
filtered_1 = FILTER A BY field3 >= 10;
filtered_2 = FILTER filtered_1  BY field4 >= 50;
grouped = GROUP filtered_2 BY field1;
B = FOREACH grouped GENERATE group as field1, SUM(A.field3)/SUM(A.field4) AS A_avg;

但我在运行上一个命令时出现了以下错误:

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

我也找不到原因,因为我在执行sum之前使用了group,而且我已经浏览了sum文档,我不知道和我写的有什么不同

wi3ka0sx

wi3ka0sx1#

grouped = GROUP filtered_2 BY field1;

grouped has no ACCESS to alias A . 

B = FOREACH grouped GENERATE group as field1, SUM(A.field3)/SUM(A.field4) AS A_avg;

"FOREACH grouped " has no access to alias A but directly to fields (field3, field4)

filtered_1 = FILTER A BY field3 >= 10;
filtered_2 = FILTER filtered_1  BY field4 >= 50;

All you are doing in this statement is an AND operation 

filtered_3 = FILTER A BY field3 >= 10 AND field4 >= 50;

Now
grouped = GROUP filtered_3 BY field1;
B = FOREACH grouped GENERATE group as field1, SUM(filtered_3.field3)/SUM(filtered_3.field4) AS A_avg;

相关问题