Flatten Operator

The FLATTEN operator looks like a UDF syntactically, but it is actually an operator that changes the structure of tuples and bags in a way that a UDF cannot. Flatten un-nests tuples as well as bags. The idea is the same, but the operation and result is different
for each type of structure.

For tuples, flatten substitutes the fields of a tuple in place of the tuple. For example, consider a relation that has a tuple of the form (a, (b, c)). The expression GENERATE $0, flatten($1), will cause that tuple to become (a, b, c).

For bags, the situation becomes more complicated. When we un-nest a bag, we create new tuples. If we have a relation that is made up of tuples of the form ({(b,c),(d,e)}) and we apply GENERATE flatten($0), we end up with two tuples (b,c) and (d,e). When
we remove a level of nesting in a bag, sometimes we cause a cross product to happen. For example, consider a relation that has a tuple of the form (a, {(b,c), (d,e)}),
commonly produced by the GROUP operator. If we apply the expression GENERATE $0, flatten($1) to this tuple, we will create new tuples: (a, b, c) and (a, d, e).

Also note that the flatten of empty bag will result in that row being discarded; no output is generated. (See alsoDrop Nulls Before a Join.)

grunt> cat empty.bag
{} 1
grunt> A = LOAD 'empty.bag' AS (b : bag{}, i : int);
grunt> B = FOREACH A GENERATE flatten(b), i;
grunt> DUMP B;
grunt>

For examples using the FLATTEN operator, see FOREACH.

版权声明:本文为博主原创文章,未经博主允许不得转载。

Pig Flatten 解包操作,解元组的更多相关文章

  1. Ruby中星号打包解包操作

    Ruby中可以使用一个星号*和两个星号**完成一些打包.解包操作,它们称为splat操作符: 一个星号:以数组为依据进行打包解包(参考文章) 两个星号:以hash为依据进行打包解包(参考文章) 两个星 ...

  2. Python_序列与映射的解包操作

    解包就是把序列或映射中每个元素单独提取出来,序列解包的一种简单用法就是把首个或前几个元素与后面几个元素分别提取出来,例如: first, seconde, *rest = sequence 如果seq ...

  3. Python 序列与映射的解包操作

    解包就是把序列或映射中每个元素单独提取出来,序列解包的一种简单用法就是把首个或前几个元素与后面几个元素分别提取出来,例如: first, seconde, *rest = sequence 如果seq ...

  4. Python 序列与映射的解包操作-乾颐堂

    解包就是把序列或映射中每个元素单独提取出来,序列解包的一种简单用法就是把首个或前几个元素与后面几个元素分别提取出来,例如: first, seconde, *rest = sequence 如果seq ...

  5. PyTricks-函数参数的解包操作

    def myfunc(x, y, z): print(x, y, z) tuple_vec = (1, 0, 1) dict_vec = {'x': 1, 'y': 0, 'z': 1} >&g ...

  6. Python - 解包的各种骚操作

    为什么要讲解包 因为我觉得解包是 Python 的一大特性,大大提升了编程的效率,而且适用性很广 啥是解包 个人通俗理解:解开包袱,拿出东西 正确理解:将元素从可迭代对象中一个个取出来 python ...

  7. 关于Python 解包,你需要知道的一切

    解包在英文里叫做 Unpacking,就是将容器里面的元素逐个取出来(防杠精:此处描述并不严谨,因为容器中的元素并没有发生改变)放在其它地方,好比你老婆去菜市场买了一袋苹果回来分别发给家里的每个成员, ...

  8. python高级特性之封包与解包

    前言 文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理. 作者:kwsy PS:如有需要Python学习资料的小伙伴可以加点击下方链接 ...

  9. Python序列解包

    元组的序列解包range对象的序列解包迭代对象的序列解包列表的序列解包字典的序列解包序列解包与遍历序列解包的其它用法 元组的序列解包 x,y,z = (1,2,3) print(x,y,z) 1 2 ...

随机推荐

  1. 在linux系统下Git源码系统的文件下载

    Git是一个开源的分布式版本控制系统,在linux系统中下载git中的文件使用repo的很多. 网上有很多repo下载的地址失效,目前可用的链接在这里记录一下. 没有安装git的安装一下: sudo ...

  2. php线程pthread实践

    php有线程吗?----有,但是需要扩展pthreads,扩展方式网上有一堆的教程,这是只做线程demo. file_put_contents(dirname(__FILE__).'/1.txt', ...

  3. linux下扩展root分区

    1 查看当前磁盘情况 fdisk -l /dev/sda1 2048 6143 2048 83 Linux /dev/sda2 * 6144 1054719 524288 83 Linux /dev/ ...

  4. Render树、RenderObject与RenderLayer

    Chapter: 呈现树的构建 1. 呈现树与CSS盒子模型千丝万缕的关系 2. 呈现树与DOM树的关系 3. 浏览器构建呈现树的流程 4. Firefox的规则树和样式上下文树 5. 规则树是如何解 ...

  5. POJ 1183 反正切函数的应用

    H - 反正切函数的应用 Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & %I64u Submit ...

  6. java深入探究01

    经过前面基础部门的学习,希望大家都把基础打闹再继续深入探究java应用层面的知识,以后的日子我会继续更新java进阶知识,深入探究实际工作中的java应用,说的不好的地方还请见谅,如果能提出你宝贵的建 ...

  7. Spark- 计算每个学科最受欢迎的老师

    日志类型 测试数据 http://bigdata.myit.com/zhangsan http://bigdata.myit.com/zhangsan http://bigdata.myit.com/ ...

  8. SpringMVC简单实例(看起来有用)

    SpringMVC简单实例(看起来有用) 参考: SpringMVC 基础教程 简单入门实例 - CSDN博客http://blog.csdn.net/swingpyzf/article/detail ...

  9. python3 字典属性

    1.字典创建 >>> D={} >>> D {} >>> D2={:,(,):::'d'}} #冒号构造 1.使用 {  }和 : 直接创建 &g ...

  10. 5_Singleton 游戏开发中的单例模式

    强制类只有一个实例 提供全局的访问 ###为什么使用: ``` 如果没有地方访问这个类,则不会创建实例 静态类在main之前实例化, 可以尝试Lazy initialization 派生单例类, 获得 ...