【问题标题】:Get next struct item from array in HIve从 HIve 中的数组中获取下一个结构项
【发布时间】:2018-05-17 23:30:29
【问题描述】:

我有一个结构数组类型字段的表:

CREATE TABLE complex_types(
   key int, 
   value ARRAY<STRUCT<status:string,method:string>>
);

INSERT INTO TABLE complex_types
SELECT row_number() over () as key,
  ARRAY(
     named_struct('status', 'OK', 'method', 'Method 1'),
     named_struct('status', 'Error', 'method', 'Method 2'),
     named_struct('status', 'Failed', 'method', 'Method 3')
  ) as value
FROM some_table LIMIT 10

当我通过索引访问整个结构时,它会返回一个正确的项目。

select key, value[0], value[1] from complex_types

结果是

key _c1 _c2
1   {"status":"OK","method":"Method 1"} {"status":"Error","method":"Method 2"}
2   {"status":"OK","method":"Method 1"} {"status":"Error","method":"Method 2"}
3   {"status":"OK","method":"Method 1"} {"status":"Error","method":"Method 2"}

但是如果我为结构项指定键,它会从最后一项返回值:

select key, value[0].method, value[1].method from complex_types

结果是

key _c1 _c2
1   Method 2    Method 2
2   Method 2    Method 2
3   Method 2    Method 2

谢谢

【问题讨论】:

  • 它对我来说很好用!

标签: hive hiveql


【解决方案1】:

更新 看起来该问题仅存在于 HDP Ambari Hive View 2.0 中。 该查询在 hive 控制台和 Ambari Hive View 1st 版本中运行良好。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-03-15
    • 1970-01-01
    • 2019-09-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多