本文介绍了Hadoop Pig UDF 调用问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的代码工作得很好,但是当我已经有两个现有的包(使用它们的别名,假设 S1 和 S2 代表两个集合的两个现有包)时,想知道如何调用 UDF setDifference 来生成集合差异?我想如果我手动构建一个额外的包,使用我已经存在的输入包(S1 和 S2),会产生额外的开销吗?

The following code works quite well, but when I already have two existing bags (with their alias, suppose S1 and S2 for representing two existing bags for two sets), wondering how to call UDF setDifference to generate set differences? I think if I manually construct an additional bag, using my already existing input bags (S1 and S2), it will be additional overhead?

register datafu-1.2.0.jar;
define setDifference datafu.pig.sets.SetDifference();

-- ({(3),(4),(1),(2),(7),(5),(6)} \t {(1),(3),(5),(12)})
A = load 'input.txt' AS (B1:bag{T:tuple(val:int)},B2:bag{T:tuple(val:int)});

F1 = foreach A generate B1;
F2 = foreach A generate B2;

differenced = FOREACH A {
  -- input bags must be sorted
  sorted_b1 = ORDER B1 by val;
  sorted_b2 = ORDER B2 by val;
  GENERATE setDifference(sorted_b1,sorted_b2);
}

-- produces: ({(2),(4),(6),(7)})
DUMP differenced;

更新:

问题是,假设我已经有两个包,如何调用 UDF setDifference 来获取集合差异?我是否需要制作另一个包含两个独立袋子的超级袋子?谢谢.

Question is, suppose I have two bags already, how to call UDF setDifference to get set differences? Do I need to build another super bag which contains the two separate bags? Thanks.

提前致谢,林

推荐答案

我没有发现 UDF 调用有任何开销问题.

I don't see any overhead issue with the UDF invocation.

参考:http://datafu.incubator.apache.org/docs/datafu/guide/set-operations.html,我们有一个使用 SetDifference 方法的例子.

Ref : http://datafu.incubator.apache.org/docs/datafu/guide/set-operations.html, we have a example for using SetDifference method.

根据 API (http://datafu.incubator.apache.org/docs/datafu/1.2.0/datafu/pig/sets/SetDifference.html) SetDifference 方法将包作为输入并发出它们之间的差异.

As per API (http://datafu.incubator.apache.org/docs/datafu/1.2.0/datafu/pig/sets/SetDifference.html) SetDifference method takes bags as input and emits the difference between them.

注意请注意,输入的袋子必须进行排序.

N.B. Do note that the input bags have to be sorted.

在共享的示例代码段中,我看不到需要以下代码段

In the example snippet shared, I don't see the need of below code snippet

F1 = foreach A generate B1;
F2 = foreach A generate B2;

这篇关于Hadoop Pig UDF 调用问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-08 02:59