我通过映射json数据创建了一个表,不幸的是,我无法读取json中的嵌套数组。
{
"total":10,
"count":100,
"values":{
"source":[{"sourceid":"10001","source":"ABC"},
{"sourceid":"10002","source":"XYZ"}
]}
}
```athena table
CREATE EXTERNAL TABLE source_master_data(
total bigint,
count bigint,
values struct<source: array<struct<sourceid: string>>>
)
ROW FORMAT SERDE 'org.openx.data.jsonserde.JsonSerDe'
LOCATION 's3://sourcemaster/'
I am trying to read the sourceid and source but no luck.. can anyone help me out
select t1.source.sourceid
from source_master_data
cross join UNNEST(source_master_data.Values) AS t1
答案 0 :(得分:0)
unnest
需要放在数组类型上。在您的查询中,您尝试取消嵌套在Athena中无法实现的结构。
第二个问题是使用values
,但不带引号。这也失败了,因为values
是雅典娜的保留字。
总体查询如下所示。
select t1.source.sourceid
from source_master_data
cross join UNNEST(source_master_data."values".source) AS t1 (source)