小组连续相当于猪? [英] group concat equivalent in pig?
本文介绍了小组连续相当于猪?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的表中,例如,我有这样的:(3fields-userid,clickcount,pagenumber)
155 | 2 | 12
155 | 3 | 133
155 | 1 | 144
156 | 6 | 1
156 | 7 | 5
期望的输出是:
155 | 2,3,1 | 12,133,144
156 | 6,7 | 1,5
如何在PIG上实现此功能?
解决方案
(156,{(6),(7)},{(1),(5)}}
grouped = GROUP table BY userid;
X = FOREACH将GENERATE组分组为userid,
table.clickcount为clicksbag,
table.pagenumber为pagenumberbag;
现在 X
将会是:
(156,{(6),(7)},{(1),(5)}}
现在您需要使用 builtin UDF BagToTuple :
output = FOREACH X GENERATE userid,
BagToTuple (clickbag)作为clickcounts,
BagToTuple(pagenumberbag)作为pagenumbers;
output
现在应该包含您想要的内容。您可以将输出步骤合并到合并步骤中:
output = FOREACH将GENERATE组分组为userid,
BagToTuple(table.clickcount)为clickcounts,
BagToTuple(table.pagenumber)为pagenumbers;
Trying to get this done on Pig. (Looking for the group_concat() equivalent of MySQL)
In my table, for example, I have this: (3fields- userid, clickcount,pagenumber)
155 | 2 | 12
155 | 3 | 133
155 | 1 | 144
156 | 6 | 1
156 | 7 | 5
The desired output is:
155| 2,3,1 | 12,133,144
156| 6,7 | 1,5
How can I achieve this on PIG?
解决方案
grouped = GROUP table BY userid;
X = FOREACH grouped GENERATE group as userid,
table.clickcount as clicksbag,
table.pagenumber as pagenumberbag;
Now X
will be:
{(155,{(2),(3),(1)},{(12),(133),(144)},
(156,{(6),(7)},{(1),(5)}}
Now you need to use the builtin UDF BagToTuple:
output = FOREACH X GENERATE userid,
BagToTuple(clickbag) as clickcounts,
BagToTuple(pagenumberbag) as pagenumbers;
output
should now contain what you want. You can merge the output step into the merge step as well:
output = FOREACH grouped GENERATE group as userid,
BagToTuple(table.clickcount) as clickcounts,
BagToTuple(table.pagenumber) as pagenumbers;
这篇关于小组连续相当于猪?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文