Pig Flatten 解包操作,解元组
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 解包操作,解元组的更多相关文章
- Ruby中星号打包解包操作
Ruby中可以使用一个星号*和两个星号**完成一些打包.解包操作,它们称为splat操作符: 一个星号:以数组为依据进行打包解包(参考文章) 两个星号:以hash为依据进行打包解包(参考文章) 两个星 ...
- Python_序列与映射的解包操作
解包就是把序列或映射中每个元素单独提取出来,序列解包的一种简单用法就是把首个或前几个元素与后面几个元素分别提取出来,例如: first, seconde, *rest = sequence 如果seq ...
- Python 序列与映射的解包操作
解包就是把序列或映射中每个元素单独提取出来,序列解包的一种简单用法就是把首个或前几个元素与后面几个元素分别提取出来,例如: first, seconde, *rest = sequence 如果seq ...
- Python 序列与映射的解包操作-乾颐堂
解包就是把序列或映射中每个元素单独提取出来,序列解包的一种简单用法就是把首个或前几个元素与后面几个元素分别提取出来,例如: first, seconde, *rest = sequence 如果seq ...
- PyTricks-函数参数的解包操作
def myfunc(x, y, z): print(x, y, z) tuple_vec = (1, 0, 1) dict_vec = {'x': 1, 'y': 0, 'z': 1} >&g ...
- Python - 解包的各种骚操作
为什么要讲解包 因为我觉得解包是 Python 的一大特性,大大提升了编程的效率,而且适用性很广 啥是解包 个人通俗理解:解开包袱,拿出东西 正确理解:将元素从可迭代对象中一个个取出来 python ...
- 关于Python 解包,你需要知道的一切
解包在英文里叫做 Unpacking,就是将容器里面的元素逐个取出来(防杠精:此处描述并不严谨,因为容器中的元素并没有发生改变)放在其它地方,好比你老婆去菜市场买了一袋苹果回来分别发给家里的每个成员, ...
- python高级特性之封包与解包
前言 文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理. 作者:kwsy PS:如有需要Python学习资料的小伙伴可以加点击下方链接 ...
- Python序列解包
元组的序列解包range对象的序列解包迭代对象的序列解包列表的序列解包字典的序列解包序列解包与遍历序列解包的其它用法 元组的序列解包 x,y,z = (1,2,3) print(x,y,z) 1 2 ...
随机推荐
- sql优化,索引学习
- java基础部分小项目
贪吃蛇项目 import java.awt.Color; import java.awt.Graphics; import java.awt.Toolkit; import java.awt.even ...
- R基础之批处理--R IN ACTION
1.5 批处理多数情况下,我们都会交互式地使用R:在提示符后输入命令,接着等待该命令的输出结果.偶尔,我们可能想要以一种重复的.标准化的.无人值守的方式执行某个R程序,例如,你可能需要每个月生成一次相 ...
- Hibernate学习---第十四节:hibernate之session线程安全
1.hibernate.cfg.xml 文件中添加如下代码开启线程安全: <property name="hibernate.current_session_context_class ...
- MySQL 当记录不存在时insert,当记录存在时update
MySQL当记录不存在时insert,当记录存在时更新:网上基本有三种解决方法 第一种: 示例一:insert多条记录 假设有一个主键为 client_id 的 clients 表,可以使用下面的语句 ...
- fastjson转对象的一些属性设置
<bean class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter"> < ...
- Android SQLite学习指南
一.SQLite简介 在Android平台上,集成了一个嵌入式关系型数据库—SQLite,SQLite3支持 NULL.INTEGER.REAL(浮点数字).TEXT(字符串文本)和BLOB(二进制对 ...
- 解决编译warning:warning: ‘MeteringUnit::voltage_gain_’ will be initialized after [-Wreorder]
问题: 环境:ubuntu 12.04,g++版本4.6.3,编译目标文件时出现warnings: u1204@u1204-zhw:~/hwsvn/2sw/4prj_mips/UCP_rt5350/s ...
- 【JVM】jvm垃圾回收器相关垃圾回收算法
引用计数法[原理]--->引用计数器是经典的也是最古老的垃圾收集防范.--->实现原理:对于对象A,只要有任何一个对象引用A,则计数器加1.当引用失效时,计数器减1.只要对象A的计数器值为 ...
- CH6802 車的放置 和 CH6B24 Place the Robots
6802 車的放置 0x60「图论」例题 描述 给定一个N行M列的棋盘,已知某些格子禁止放置.问棋盘上最多能放多少个不能互相攻击的車.車放在格子里,攻击范围与中国象棋的"車"一致. ...