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.

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

最新文章

  1. 使用Navicat导入导出表的数据做测试(转载)
  2. PHP isset 函数作用
  3. Support Vector Machines for classification
  4. Android更改imagebutton为纯色方法
  5. mvc 路由 使用
  6. GitHub上最火的40个iOS开源项目
  7. Xamarin For Visual Studio 3.7.165 完整离线破解版
  8. Android IPC机制全解析<一>
  9. python - dict.setdefault
  10. ASP.NET MVC编程——控制器
  11. Android 网络图片加载之cude 框架
  12. telnet操作memcache
  13. U盘安装CentOS系统、raid5制作以及nohup的使用
  14. struts2+springmvc+hibernate开发。个人纪录
  15. MongpDB 学习手册 - 索引
  16. 大话前端解析Json对象
  17. js实现的map方法
  18. 在java代码中执行js脚本,实现计算出字符串“(1+2)*(1+3)”的结果
  19. [转]Centos7下面配置静态IP
  20. HDU 2391 Filthy Rich (dp)

热门文章

  1. bigdecimal类型除法问题
  2. delphi通过Idhttp和php交互
  3. bzoj 1579: [Usaco2009 Feb]Revamping Trails 道路升级 优先队列+dij
  4. Oracle数据库操作语言(DML)
  5. java:Map借口及其子类HashMap四
  6. 修改(python) mysql 数据库 使其可以支持插入中文
  7. uva 111 History Grading(lcs)
  8. WebElement接口获取值
  9. Tomcat_异常_03_Tomcat日志(Logger)中文乱码
  10. 理解SetCapture()和ReleaseCapture()及GetCapture()作用