从 Athena 读取 Json 数据
Reading Json data from Athena
我通过映射 json 数据创建了一个 table,不幸的是我无法读取 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
unnest
需要放在数组类型上。在您的查询中,您试图取消嵌套 Athena 中不可能的结构。
第二个问题是不带引号的 values
的使用。这也失败了,因为 values
是 Athena 中的保留字。
整个查询看起来像这样。
select t1.source.sourceid
from source_master_data
cross join UNNEST(source_master_data."values".source) AS t1 (source)
我通过映射 json 数据创建了一个 table,不幸的是我无法读取 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
unnest
需要放在数组类型上。在您的查询中,您试图取消嵌套 Athena 中不可能的结构。
第二个问题是不带引号的 values
的使用。这也失败了,因为 values
是 Athena 中的保留字。
整个查询看起来像这样。
select t1.source.sourceid
from source_master_data
cross join UNNEST(source_master_data."values".source) AS t1 (source)