0

在 Hadoop 中,我有很多看起来像这样: (item_id,owner_id,counter)- 可能有重复,但总是item_id有相同的owner_id

我想获得counter每个的总和,item_id所以我有以下脚本:

alldata = LOAD '/path/to/data/*' USING D; -- D describes the structure
known_items = FILTER alldata BY owner_id > 0L;
group_by_item = GROUP known_data BY (item_id);
data = FOREACH group_by_item GENERATE group AS item_id, OWNER_ID_COLUMN_SOMEHOW, SUM(known_items.counter) AS items_count;

问题在于,FOREACH如果我想采取known_items.owner_id- 那将是一个包含所有分组之和的元组item_id。获得第一个所有者的最有效方法是什么?

4

1 回答 1

1

如果您认为每个item_id人都有相同的假设owner_id是正确的,那么最简单的解决方案会给您正确的答案,并且如果不是,则会让您知道:将owner_id包括为组的一部分。

alldata = LOAD '/path/to/data/*' USING D; -- D describes the structure
known_items = FILTER alldata BY owner_id > 0L;
group_by_item = GROUP known_data BY (item_id, owner_id);
data = FOREACH group_by_item GENERATE FLATTEN(group), SUM(known_items.counter) AS items_count;
于 2013-01-11T15:22:10.210 回答