0

我有个问题。我不明白如何为输入生成唯一的“交叉”。这是我的输入:

A, B, C

我想得到:

A,B
A,C
B,C

我可以使用什么 UDF(data-fu,piggybank)来解决这个问题?

4

1 回答 1

1

如果你的输入就像

A
B
C

和你想输出:

A,B
A,C
B,C

您可以使用crossjoin 来获取结果。例如:

input1 = load 'your_path' as (key: chararray);
input2 = load 'your_path' as (key: chararray);
cross_results = cross input1, input2;
final_results = filter cross_results by input1::key < input2::key;

如果 "A,B,C" 只是一个记录中的一个包,您可以使用flatten. 例如,

-- Assume your input x is something like {A, B, C} in one row
y = foreach x generate flatten($0) as f1, flatten($0) as f2;
final_results = filter y by f1 < f2;

由于您的描述不是很详尽,我只能提供上述解决方案。您可能需要对其进行调整。

于 2013-07-04T12:55:35.403 回答