【发布时间】: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
谢谢
【问题讨论】:
-
它对我来说很好用!