本文介紹了豬中的組串聯等價物?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
試圖在 Pig 上完成這項工作.(尋找相當于 MySQL 的 group_concat())
Trying to get this done on Pig. (Looking for the group_concat() equivalent of MySQL)
例如,在我的表中,我有這個:(3fields- userid, clickcount,pagenumber)
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
所需的輸出是:
155| 2,3,1 | 12,133,144
156| 6,7 | 1,5
我怎樣才能在 PIG 上實現這一點?
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;
現在 X
將是:
{(155,{(2),(3),(1)},{(12),(133),(144)},
(156,{(6),(7)},{(1),(5)}}
現在您需要使用 內置 UDF BagToTuple:
output = FOREACH X GENERATE userid,
BagToTuple(clickbag) as clickcounts,
BagToTuple(pagenumberbag) as pagenumbers;
output
現在應該包含您想要的內容.您也可以將輸出步驟合并到合并步驟中:
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;
這篇關于豬中的組串聯等價物?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!