如何在 Apache Pig 中使用 2 个 for 循环

How to use 2 for loops in apache pig

如何在 Apache Pig 中使用 2 个 for 循环?

我输入的数据如下:

1  a 3
15 b 4
1  b 2
25 a 5
15 c 3
1  a 3
15 c 2
25 b 4

中间输出:对于 1 计数总数。 a 和 b,15 和 25 相似

1 a 6
1 b 2
15 b 4
15 c 5
25 a 5
25 b 4

最终输出:需要 1 个最大计数

1 a 6
15 c 5
25 a 5
A = load 'test.input' using PigStorage() as (index:int, id:chararray, count:int);
B = GROUP A by (index, id);
C = FOREACH B GENERATE flatten(group), SUM(A.count) as sum;

store C into '/tmp/intermediate';

D = GROUP C by index;

E = FOREACH D {
    ORDERED_C = order C by sum DESC;
    LIMIT_C = LIMIT ORDERED_C 1;
    GENERATE FLATTEN(LIMIT_C);  -- flatten to take out the unnecessary bag
}
store E into '/tmp/final';