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