[英]Defining schema for nested JSON structures in AWS Athena
我嵌套了 json 格式如下:
{
"id": "212",
"profile": "unknown",
"role":
"{
"admin_role": "yes",
"developer_role":"yes"
}"
}
我的目标是在创建表时定义架构,但由于数据以字符串形式提供,因此面临角色错误。
期待:
CREATE EXTERNAL TABLE profile
id bigint,
profile string,
role struct<
admin_role:string,
developer_role:string
>
row format serde 'org.openx.data.jsonserde.JsonSerDe'
location 's3://<bucket_name>/<path>';
在第一级表创建本身定义角色架构的任何建议?
谢谢
您的 JSON 存在问题,如下所示更正后可以查询。 确保每个 JSON 记录在单独的行上。
{"id":"212","profile":"unknown","role":{"admin_role":"yes","developer_role":"yes"}}
用于查询 JSON 的 DDL:
CREATE EXTERNAL TABLE `sf_73855155`(
`id` string COMMENT 'from deserializer',
`profile` string COMMENT 'from deserializer',
`role` struct<admin_role:string,developer_role:string> COMMENT 'from deserializer')
ROW FORMAT SERDE
'org.openx.data.jsonserde.JsonSerDe'
WITH SERDEPROPERTIES (
'paths'='id,profile,role')
STORED AS INPUTFORMAT
'org.apache.hadoop.mapred.TextInputFormat'
OUTPUTFORMAT
'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'
LOCATION '<path>'
Output:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.