zoukankan      html  css  js  c++  java
  • 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.

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

  • 相关阅读:
    监听器模式
    接口幂等性实现
    如何设计一个良好的API接口
    接口重试实现
    Spring不常用但有用的注解
    angular项目语言切换功能
    解决IOS上传竖向照片会旋转90度的问题
    微信点击链接:debugx5.qq.com提示您使用的不是x5内核
    swagger注释@API详细说明
    创建swap虚拟内存分区
  • 原文地址:https://www.cnblogs.com/jamesf/p/4751586.html
Copyright © 2011-2022 走看看