Pig|Pig FOREACH 嵌套循环
Example: Nested Block Suppose we have relations A and B. Note that relation B contains an inner bag.
A = LOAD 'data' AS (url:chararray,outlink:chararray); DUMP A; (www.ccc.com,www.hjk.com) (www.ddd.com,www.xyz.org) (www.aaa.com,www.cvn.org) (www.www.com,www.kpt.net) (www.www.com,www.xyz.org) (www.ddd.com,www.xyz.org)B = GROUP A BY url; DUMP B; (www.aaa.com,{(www.aaa.com,www.cvn.org)}) (www.ccc.com,{(www.ccc.com,www.hjk.com)}) (www.ddd.com,{(www.ddd.com,www.xyz.org),(www.ddd.com,www.xyz.org)}) (www.www.com,{(www.www.com,www.kpt.net),(www.www.com,www.xyz.org)})
In this example we perform two of the operations allowed in a nested block, FILTER and DISTINCT. Note that the last statement in the nested block must be GENERATE. Also, note the use of projection (PA = FA.outlink; ).
X = FOREACH B { FA= FILTER A BY outlink == 'www.xyz.org'; PA = FA.outlink; DA = DISTINCT PA; GENERATE group, COUNT(DA); }DUMP X; (www.aaa.com,0) (www.ccc.com,0) (www.ddd.com,1) (www.www.com,1)
版权声明:本文为博主原创文章,未经博主允许不得转载。
【Pig|Pig FOREACH 嵌套循环】转载于:https://www.cnblogs.com/jamesf/p/4751587.html
推荐阅读
- mybatisplus|mybatisplus where QueryWrapper加括号嵌套查询方式
- Improve|Improve Nested Conditionals(优化嵌套的条件语句) 面对大量的if-else语句
- JavaScript|JavaScript — 初识数组、数组字面量和方法、forEach、数组的遍历
- 表观遗传epigenetic|表观遗传epigenetic inheritance
- CBB1007
- 集合框架(集合嵌套存储和遍历元素的案例代码实现)
- markdown中使用iframe|markdown中使用iframe 嵌套网页
- 看《Peppa|看《Peppa Pig》学英语(三)
- 儿童学编程语言swift语言|儿童学编程语言swift语言 playgrounds12 嵌套模式
- MyBatis中使用foreach循环的坑及解决