使用pig拉丁语将数组转置到行

hwamh0ep  于 2021-06-24  发布在  Pig
关注(0)|答案(1)|浏览(452)

如何将包中的arry元素转换为多行例如:下面
我的意见:
元组,数组元素(32,{(1,emp,3271409712),(2,emp,3271409712)})
输出(32,1,emp,3271409712)(32,2,emp,3271409712)

myzjeezk

myzjeezk1#

你可能需要打两次电话。注意,在元组上展平只是将元组中的每个字段提升到顶级字段。flatte on bag生成包中每个记录与generate中所有其他表达式的叉积。

A = load 'test.txt' using PigStorage() as (a0:int, t1:(a1:int, b1 {(a3:int,a4:chararray,a5:chararray)}));
describe A;
B = FOREACH A GENERATE FLATTEN(t1);  
describe B;
C = FOREACH B GENERATE a1, FLATTEN(b1);
describe C;
dump C;

输出

A: {a0: int,t1: (a1: int,b1: {(a3: int,a4: chararray,a5: chararray)})}
B: {t1::a1: int,t1::b1: {(a3: int,a4: chararray,a5: chararray)}}
C: {t1::a1: int,t1::b1::a3: int,t1::b1::a4: chararray,t1::b1::a5: chararray}
(32,1,emp,3271409712)
(32,2,emp,3271409712)

相关问题