zoukankan      html  css  js  c++  java
  • hive explode 行拆列

    创建一张表test_explode,表结构如下

    表数据如下:

    1.使用explode函数

    select explode(friends) as friend from test_explode;
    

    但是只使用explode函数很难满足实际需求,原因如下:

      1.1 No other expressions are allowed in SELECT

    0: jdbc:hive2://master01.hadoop.mobile.cn:1> select name,explode(friends) as friend from test_explode;
    Error: Error while compiling statement: FAILED: SemanticException [Error 10081]: UDTF's are not supported outside the SELECT clause, nor nested in expressions (state=42000,code=10081)
    

       1.2 UDTF's can't be nested

       1.3 GROUP BY / CLUSTER BY / DISTRIBUTE BY / SORT BY is not supported

    2 配合LATERAL VIEW 解除限制

    select name,sex,phone,friend from test_explode LATERAL VIEW explode(friends) myTable1 AS friend ;
    

    结果如下:

  • 相关阅读:
    [TEST123] Performance Test
    [XML123] FpML
    [Java123] Java中的System.exit
    【大秦帝国123】
    1_1:编程概念 + 计算机基础
    响应式布局
    苏宁首页demo
    rem适配方案
    less的使用
    rem布局
  • 原文地址:https://www.cnblogs.com/zz-ksw/p/11347448.html
Copyright © 2011-2022 走看看