我想知道是否可以通过使用基本的PIG LATIN语句来模仿COGROUP的结果?
提前致谢。
答案 0 :(得分:0)
你是什么意思"模仿COGROUP的结果" ?
Pig Latin语言已经具有COGROUP的功能。
示例:
COGROUP alias BY (col1, col2)
COGROUP通常在涉及多个关系时使用。
答案 1 :(得分:0)
我想知道你为什么需要这样做?以下代码适用于2个别名
>cat test1
1,aaaa
2,bbbb
3,cccc
4,dddd
5,eeee
6,ffff
7,gggg
8,hhhh
9,iiii
>cat test2
7,ggggggg
8,hhhhhhh
9,iiiiiii
10,jjjjjjj
11,kkkkkkk
7,9999
7,gggg
grunt>test1 = load 'test1' USING PigStorage(',') as (id: int, val: chararray);
grunt>test2 = load 'test2' USING PigStorage(',') as (id: int, val: chararray);
grunt>cgrp = cogroup test1 by id, test2 by id;
grunt>dump cgrp;
我们有
(1,{(1,aaaa)},{})
(2,{(2,bbbb)},{})
(3,{(3,cccc)},{})
(4,{(4,dddd)},{})
(5,{(5,eeee)},{})
(6,{(6,ffff)},{})
(7,{(7,gggg)},{(7,ggggggg),(7,9999),(7,gggg)})
(8,{(8,hhhh)},{(8,hhhhhhh)})
(9,{(9,iiii)},{(9,iiiiiii)})
(10,{},{(10,jjjjjjj)})
(11,{},{(11,kkkkkkk)})
以下代码可以给出相同的结果
grunt>g1 = group test1 by id;
grunt>g2 = group test2 by id;
grunt>j = join g1 by group FULL, g2 by group;
grunt>j2 = foreach j generate (g1::group is null ? g2::group : g1::group), (test1 is null? (bag{tuple(int, chararray)}){} : test1) as test1, (test2 is null? (bag{tuple(int,chararray)}){} : test2) as test2;