CROSS 演算子が必要です。次に例を示します。
入力
1,2
1,1
1,3
1,4
2,5
2,3
2,6
コード
inpt = load 'parent_child.csv' using PigStorage(',') as (parent_id: long, child_id: long);
tmp = foreach inpt generate parent_id, child_id as b1, child_id as b2; -- needed to use CROSS in the nested FOREACH
parentGroup = group tmp by parent_id;
perms = foreach parentGroup {
bro_1 = tmp.b1;
bro_2 = tmp.b2;
brothers = cross bro_1, bro_2;
brothers = filter brothers by b1 != b2; -- remove relationship to itself
generate group as parent_id, brothers;
}
出力
スキーマ - perms: {parent_id: long,brothers: {(bro_1::b2: long,bro_2::b2: long)}}
(1,{(1,2),(3,2),(4,2),(2,1),(3,1),(4,1),(2,3),(1,3),(4,3),(2,4),(1,4),(3,4)})
(2,{(3,5),(6,5),(5,3),(6,3),(5,6),(3,6)})