猪:旋转&总和3关系 [英] Pig: Pivoting & Sum 3 relations
本文介绍了猪:旋转&总和3关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有3种不同的关系,如下所述&我可以使用UDF获得输出,但在PIG中寻找实现。在论坛中提到了其他的东西,但没有得到这个问题的具体想法。
过程:
FN1,10
$
FN2, 20
FN3,23
FN4,25
FN5,15
FN7,40
FN10,56
FN1,12
FN2, 13
FN3,33
FN6,60
FN8,23
FN9,44
FN10,4
AllFN:
FN1
FN2
FN3
FN4
FN5
FN6
FN7
FN8
FN9
FN10
需要的输出是:
FN1,10,12, 22
FN2,20,13,33
FN3,23,33,56
FN4,25,0,25
FN5,15,0,15
FN6 ,0,60,60
FN7,40,0,40
FN8,0,23,23
FN9,0,44,44
FN10,56,4,60
解决方案在test.txt中测试你的关系test2.txt和test3.txt
A =使用PigStorage(',')加载'test.txt';
B =使用PigStorage(',')加载'test2.txt';
C =使用PigStorage(',')加载'test3.txt';
D = COGROUP A减$ 0,B减$ 0;
E = COGROUP C减$ 0,D减$ 0;
F = FOREACH E生成$ 0,FLATTEN(D.A),FLATTEN(D.B);
G = FOREACH F生成$ 0,$ 1. $ 1,$ 2. $ 1; $(b)$ H = FOREACH G生成$ 0,FLATTEN((IsEmpty($ 1)?null:$ 1)),FLATTEN((IsEmpty($ 2)?null:$ 2));
I = foreach H生成$ 0,($ 1为null?0:$ 1),($ 2为null?0:$ 2),($ 1为null?0:$ 1)+($ 2为null?$ 0:$ 2) ;
转储I;
输出
(FN1,10,12,22)
(FN2,20,13,33)
(FN3,23,33,56)
(FN4,25,0, )
(FN5,15,0,)
(FN6,0,60,60)
(FN7,40,0,)
(FN8,0,23,23) )
(FN9,0,44,44)
(FN10,56,4,60)
i have 3 different relations as mentioned below & i can get the output using UDFs but looking for implementation in PIG. Referred other stuff in the forums but not getting concrete idea over this problem.
Proc:
FN1,10 FN2,20 FN3,23 FN4,25 FN5,15 FN7,40 FN10,56
Rej:
FN1,12 FN2,13 FN3,33 FN6,60 FN8,23 FN9,44 FN10,4
AllFN:
FN1 FN2 FN3 FN4 FN5 FN6 FN7 FN8 FN9 FN10
Output required is:
FN1,10,12,22 FN2,20,13,33 FN3,23,33,56 FN4,25,0,25 FN5,15,0,15 FN6,0,60,60 FN7,40,0,40 FN8,0,23,23 FN9,0,44,44 FN10,56,4,60
解决方案Asumming your relations are in test.txt test2.txt and test3.txt
A = LOAD 'test.txt' using PigStorage(','); B = LOAD 'test2.txt' using PigStorage(','); C = LOAD 'test3.txt' using PigStorage(','); D = COGROUP A by $0, B by $0; E = COGROUP C by $0, D by $0; F = FOREACH E generate $0, FLATTEN(D.A), FLATTEN(D.B); G = FOREACH F generate $0, $1.$1, $2.$1; H = FOREACH G generate $0, FLATTEN((IsEmpty($1)?null:$1)), FLATTEN((IsEmpty($2)?null:$2)); I = foreach H generate $0, ($1 is null?0:$1),($2 is null?0:$2),($1 is null?0:$1)+($2 is null?$0:$2); dump I;
Output
(FN1,10,12,22) (FN2,20,13,33) (FN3,23,33,56) (FN4,25,0,) (FN5,15,0,) (FN6,0,60,60) (FN7,40,0,) (FN8,0,23,23) (FN9,0,44,44) (FN10,56,4,60)
这篇关于猪:旋转&总和3关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文