从HIve中的数组中获取下一个struct项

时间:2018-05-17 06:46:18

标签: hive hiveql

我有一个包含结构数组字段的表:

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

谢谢

1 个答案:

答案 0 :(得分:0)

<强>更新 看起来这个问题仅存在于HDP Ambari Hive View 2.0中。 该查询在蜂巢控制台和Ambari Hive View 1st版本中工作正常。

相关问题