我已经从HDFS加载了2个排序的数据包。现在,我想执行合并联接或对其设置相交以返回(3, Storm 的孤儿),(7,Muriel的婚礼)。

我在使用Datafu或Pig Mergejoin功能时遇到了一些问题。

我尝试了如下所述的天真的解决方案,但它没有利用我的数据进行排序。

vegas = LOAD 'vegas' USING PigStorage() AS (B1:bag{T1:tuple(id:int, name:chararray)});
macau = LOAD 'macau' USING PigStorage() AS (B2:bag{T2:tuple(id:int, name:chararray)});
vegast = FOREACH vegas GENERATE FLATTEN(vegas.$0) AS (id:int,name:chararray);
macaut = FOREACH hotel GENERATE FLATTEN(macau.$0) AS (id:int,name:chararray);

F = join vegast by id, macaut by id;
-- o/p: (3,Orphans of the Storm), (7,Muriel's Wedding)
-- describe vegas
--vegas: {B1: {T1: (id: int,name: chararray)}}
-- data for vegas
--({(3,Orphans of the Storm),(6,One Magic Christmas),(7,Muriel's Wedding),(8,Mother's Boys),(9,Nosferatu: Original Version)})

-- describe macau
--macau: {B1: {T1: (id: int,name: chararray)}}
--data for macau
--({(1,The Nightmare Before Christmas),(3,Orphans of the Storm),(4,The Object of Beauty),(7,Muriel's Wedding)})

有人可以建议找到用 pig 分类的两个袋子相交的最佳方法是什么?

最佳答案

我们Xplenty(Hadoop平台即服务)在袋上进行集合操作时存在相同的问题,因此我们决定走简单的道路,并在JRuby UDF中实现集合操作。

为了执行它,您需要在节点上安装jruby。

此处查看代码:https://gist.github.com/saggineumann/9804083

09-25 20:19