3

在猪中,我将我的数据按摩成如下内容:

(a,{(b,c),(d,e),(f,g)})
(h,{(i,j),(k,l)})

其中第一项是组,袋子是与组相关的其他值。我想把它变成以下格式:

(a,b,c,d,e,f,g)
(h,i,j,k,l)

我到了现在的位置

grunt> j = foreach G {            
>>     o = order myvar by second;
>>     generate group, o.(first,second);
>> };

所以包中的元组当前是有序的。如果我做类似的事情,mystuff = foreach j generate group, flatten($1);我会把它全部展平和不分组。

这在猪中是否可行,如果可以,我应该查看什么命令?

4

1 回答 1

3

我无法做到开箱即用。您确实需要为此使用用户定义的函数。我知道这很糟糕,因为您必须编写 Java 或 Python 代码,但是您会发现 Pig 还远远不够的几种情况。Pig 可以被认为是一种数据流语言,而不是一种编程语言,这就是 UDF 发挥如此重要作用的原因:它们弥合了差距。

我的建议是你写一个UDF,它接受group和值包作为参数。在 UDF 中进行排序/排序以及展平。


The other thing you want to be careful about is that now your rows will have different numbers of columns and Pig doesn't really like this. If you are just immediately outputting it, you can probably get away with this. You might want to consider having your UDF write out the list in a tab-delimited string or something that is preformatted. This isn't that big of a deal... feel free to ignore my advice here.

于 2012-08-12T23:50:03.287 回答