Map PIG-使用PIG拉丁语实现COGROUP

Map PIG-使用PIG拉丁语实现COGROUP,map,mapreduce,apache-pig,Map,Mapreduce,Apache Pig,我想知道是否有可能通过使用基本的PIG拉丁语句来模仿COGROUP的结果 提前谢谢。你说的“模仿COGROUP的结果”是什么意思 猪拉丁语已经有了一个功能 例如: COGROUP alias BY (col1, col2) COGROUP通常在涉及多个关系时使用。我想知道为什么需要这样做?以下代码适用于alias 2 >cat test1 1,aaaa 2,bbbb 3,cccc 4,dddd 5,eeee 6,ffff 7,gggg 8,hhhh 9,iiii >cat tes

我想知道是否有可能通过使用基本的PIG拉丁语句来模仿COGROUP的结果

提前谢谢。

你说的“模仿COGROUP的结果”是什么意思

猪拉丁语已经有了一个功能

例如:

COGROUP alias BY (col1, col2)

COGROUP通常在涉及多个关系时使用。

我想知道为什么需要这样做?以下代码适用于alias 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;

对我知道。有没有办法实现它的功能?@Maddy你是什么意思?我想模仿一下它的功能。我知道我们可以使用COGROUP命令,但我想使用一系列原始PIG脚本行来模拟它。例如,我们可以使用COGROUP:1模拟连接函数。在公共键上的两个关系之间使用COGROUP。2.展平所需字段以模拟结果。是否有任何方法可以使用PIG中的任何其他命令来模拟COGROUP?