如何在组合包中展平元组

时间:2017-07-14 18:14:41

标签: apache-pig

假设我们在test_file中有以下数据:

1, 3, 4
1, 5, 6

以及以下脚本:

r1 = load 'test_file' using PigStorage(',') as (a:int, b:int, c:int);

r2 = foreach r1 generate a, (b, c) as bc;

r2_group = group r2 by a;

r3 = foreach r2_group generate group as a, r2.bc as bc; 

r3如下所示:

(1, {((3, 4)), ((5,6))})

那么,我如何修改上面的脚本以生成类似下面的内容?

(1, ((3,4), (5,6)))

1 个答案:

答案 0 :(得分:0)

看起来以下代码可以解决问题:

r4 = foreach r3 {
    tmp = BagToTuple(bc);
    generate a as a,
        tmp as bc;
}

r4如下所示:

(1,((5,6),(3,4)))