これを行うには、ネストされた LIMIT を指定した GROUP BY、FOREACH、および JOIN または COGROUP を使用する必要があります。Pig 0.10 の実装を参照してください。入力データを使用して、指定された出力を取得しました。
A = load '~/pig/data/subset_join_A.dat' as (k:chararray, m:chararray, n:chararray);
B = load '~/pig/data/subset_join_B.dat' as (o:chararray, p:int);
-- as join will be on m, we need to leave only 2 rows per a value in m.
group_A = group A by m;
top_A_x = foreach group_A {
top = limit A 2; -- where x = 2
generate flatten(top);
};
-- another way to do join, allows us to do left or right joins and checks
co_join = cogroup top_A_x by (m), B by (o);
-- filter out records from A that are not in B
filter_join = filter co_join by IsEmpty(B) == false;
result = foreach filter_join generate flatten(top_A_x);
または、入れ子になった LIMIT を使用して、COGROUP、FOREACH だけで実装することもできます。
A = load '~/pig/data/subset_join_A.dat' as (k:chararray, m:chararray, n:chararray);
B = load '~/pig/data/subset_join_B.dat' as (o:chararray, p:int);
co_join = cogroup A by (m), B by (o);
filter_join = filter co_join by IsEmpty(B) == false;
result = foreach filter_join {
top = limit A 2;
--you can limit B as well
generate flatten(top);
};