我有两组元组,我想通过第一个元素将它们连接起来并将其他部分合并为一个元组,想知道如何在Hadoop上的Pig中实现它?
输入两个元组集,
1,(1,2)
2,(2,3)
1,(b,c,b,c)
2,(c,d,c,d)
预期产出,
1,(1,2,b,c,b,c)
2,(2,3,c,d,c,d)
提前谢谢,
林
答案 0 :(得分:1)
值得考虑的想法......
输入:
dataA:
1 (1,2)
2 (2,3)
<强>数据B:强>
1 (b,c,b,c)
2 (c,d,c,d)
猪脚本:
A = LOAD 'dataA' USING PigStorage('\t') AS (aid:long, atuple : tuple(af1:long, af2:long));
B = LOAD 'dataB' USING PigStorage('\t') AS (bid:long, btuple : tuple(bf1:chararray, bf2:chararray, bf3:chararray, bf4:chararray));
C = JOIN A BY aid, B BY bid;
D = FOREACH C GENERATE aid AS id, FLATTEN(atuple) AS (af1:long, af2:long) , FLATTEN(btuple) AS (bf1:chararray, bf2:chararray, bf3:chararray, bf4:chararray);
E = FOREACH D GENERATE id, (af1..bf4);
DUMP E;
输出:DUMP E:
(1,(1,2,b,c,b,c))
(2,(2,3,c,d,c,d))