9

我在 Pig 中有这段代码(win、request 和 response 只是直接从文件系统加载的表):

win_request = JOIN win BY bid_id, request BY bid_id;
win_request_response = JOIN win_request BY win.bid_id, response BY bid_id;

win_group = GROUP win_request_response BY (win.campaign_id);

win_count = FOREACH win_group GENERATE group, SUM(win.bid_price);

基本上我想在加入和分组后对 bid_price 求和,但出现错误:

Could not infer the matching function for org.apache.pig.builtin.SUM as multiple or none of them fit. Please use an explicit cast.

我的猜测是我没有正确引用win.bid_price.

4

1 回答 1

7

在执行多个连接时,我建议为您的字段使用唯一标识符(例如,对于 bid_id)。或者,您也可以使用消歧运算符'::',但这可能会变得很脏。

wins = LOAD '/user/hadoop/rtb/wins' USING PigStorage(',') AS (f1_w:int, f2_w:int,  f3_w:chararray);
reqs = LOAD '/user/hadoop/rtb/reqs' USING PigStorage(',') AS (f1_r:int, f2_r:int, f3_r:chararray);
resps = LOAD '/user/hadoop/rtb/resps' USING PigStorage(',') AS (f1_rp:int, f2_rp:int, f3_rp:chararray);

wins_reqs = JOIN wins BY f1_w, reqs BY f1_r;
wins_reqs_reps = JOIN wins_reqs BY f1_r, resps BY f1_rp;

win_group = GROUP wins_reqs_reps BY (f3_w);

win_sum = FOREACH win_group GENERATE group, SUM(wins_reqs_reps.f2_w);
于 2012-10-31T16:44:04.983 回答