首页 文章

Amazon athena无法读取S3 JSON对象文件,而Athena select查询返回JSON键列的空结果集

提问于
浏览
1

我在Athena创建了一个具有以下结构的 table

CREATE EXTERNAL TABLE s3_json_objects (
    devId string,
    type string,
    status string
)
ROW FORMAT SERDE 'org.openx.data.jsonserde.JsonSerDe'
WITH SERDEPROPERTIES ( 'ignore.malformed.json' = 'true')
LOCATION 's3://mybucket/folder1/data/athena_test/';

S3存储桶对象包含像这样的JSON结构{
“devId”:“00abcdef1122334401”,
“type”:“lora”,
“身份”:“huihuhukiyg”
}

但是,在SQL下正常工作并返回正确的结果仅 count

SELECT count(*) as total_s3_objects FROM "athena_db"."s3_json_objects"

但是每当我在下面查询SQL select语句以从S3获取JSON值时,它返回的结果集为SELECT SELECT devid FROM“athena_db”列 . “s3_json_objects”
SELECT json_extract(devid,'$ .devid')as Id FROM“athena_db” . “s3_json_objects”
SELECT * FROM“athena_db” . “s3_json_objects”

此外,我在StackOverflow和AWS Athena doc上发布此问题之前查看这些链接

Can't read json file via Amazon Athena

AWS Athena json_extract query from string field returns empty values

任何意见或建议将不胜感激 .

2 回答

  • 1

    JSON必须在一行中,如this page of the AWS Athena documentation中所述 . 您可以在单独的行上拥有多个JSON对象,但每个完整对象只能跨越一行 .

    示例(这可能都在一个S3对象中):

    {"devId": "a1", "type": "b1", "status": "c1"}
    {"devId": "a2", "type": "b2", "status": "c2"}
    
  • 1

    胶水可以读取多行json对象,因为它有引擎盖下的火花引擎 . 一种解决方法是,如果你不能轻易地将这些json对象放在线上,使用胶水将这些json对象转换为镶木地板 .

相关问题