猪错误中的AVG()

时间:2016-02-27 17:11:17

标签: apache-pig

我的代码:

table = load '/tmp/baseball/Salaries.csv' using PigStorage(',') AS (yearID,teamID,lgID,playerID,salary);
table2 = load '/tmp/baseball/Fielding.csv' using PigStorage(',') AS      (playerID,yearID,stint,teamID,lgID,Pos,G,GS,InnOuts,PO,A,E,DP,PB,WP,SB,CS,ZR);
combined_table = JOIN table by (yearID,playerID),table2 by (yearID,playerID);
combined_table_grped = GROUP combined_table BY Pos;
avg = FOREACH combined_table_grped GENERATE     combined_table.Pos,AVG(combined_table.salary);
dump avg;

但我得到了这个:

<file 5_avg_salary_2.pig, line 5, column 57> Multiple matching functions for org.apache.pig.builtin.AVG with input schema: ({{(bytearray)}}, {{(double)}}). Please use an explicit cast.

我一般对使用AVG感到困惑。从理论上讲,我的代码应该有用......有人能帮帮我吗?感谢!!!

1 个答案:

答案 0 :(得分:0)

这是字段类型不匹配的问题。尝试将colomn类型初始化为double。因为默认类型是bytearray.you也可以使用显式强制转换将结果存储为double,因为默认的bytearray会抛出错误,如下所示。