hadoop - 如何在 apache pig 中使用 2 个 for 循环
问题描述
如何在 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';
推荐阅读
- python - 如何在一系列输入中绘制张量流激活函数
- c# - 有可执行文件,但需要识别源代码
- amazon-web-services - AWS EMR 无法从 S3 存储桶中找到映射器文件 - 没有这样的文件或目录
- facebook - Facebook 洞察 API 仅在一周前推出
- reactjs - 用户可以以任何方式看到未渲染的 React 组件吗?
- java - Tomcat 在同一个 JVM 中不能有多个实例,但在同一个物理框内?
- .net - 是否可以从 Web 服务 .asmx 调用 rest api?
- visual-studio - 带有 cmake 的 Cuda
- python - 如何在 python 的循环中创建自定义语句?
- scala - Spark - 将整行传递给 udf,然后在 udf 中获取列名