我有这样一组元组
A = (1, ["Football","Baseball"]) (2, ["Swimming","Baseball"])
我想根据字符串数组拆分元组,这样最终的结果是这样的
(1, "Football") (1, "Baseball") (2, "Swimming") (2, "Baseball")
我怎样才能在Pig身上做到这一点?
j9per5c41#
首先拆下 '[' 以及 ']' 使用 REPLACE 函数,然后将输出 Package 到 bag 以及 flatten 是的。输入
'['
']'
REPLACE
bag
flatten
1,["Football","Baseball"] 2,["Swimming","Baseball"]
Pig手稿:
A = LOAD 'input' USING PigStorage(',') AS (f1:int,f2:chararray,f3:chararray); B = FOREACH A GENERATE f1,FLATTEN(TOBAG(REPLACE(f2,'[\\[\\]]',''),REPLACE(f3,'[\\[\\]]',''))); DUMP B;
输出:
(1,"Football") (1,"Baseball") (2,"Swimming") (2,"Baseball")
1条答案
按热度按时间j9per5c41#
首先拆下
'['
以及']'
使用REPLACE
函数,然后将输出 Package 到bag
以及flatten
是的。输入
Pig手稿:
输出: