Amazon athena 无法读取 S3 JSON 对象文件和 Athena select 查询 returns JSON 键列的空结果集

Amazon athena can't read S3 JSON Object files and Athena select query returns empty result sets for JSON key columns

我在 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 bucket objects contains JSON structure like this

{
    "devId": "00abcdef1122334401",
    "type": "lora",
    "status": "huihuhukiyg"
}

但是下面 SQL 工作正常并且 return 只有 count[=23= 的正确结果]

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

BUT whenever I query below SQL select statement to fetch the JSON values from S3, It's returns result sets with empty values for columns

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"

此外,我在 post Whosebug 上的这个问题和 AWS Athena doc

之前查看了这些链接

Can't read json file via Amazon Athena

AWS Athena json_extract query from string field returns empty values

如有任何意见或建议,我们将不胜感激。

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

示例(这可以全部在一个 S3 对象中):

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

Glue 可以读取多行 json 对象,因为它的引擎盖下有火花引擎。一种解决方法是,如果您无法轻松在线制作这些 json 对象,请使用胶水将这些 json 对象转换为镶木地板。

使用 jsonlines 将 JSON 转换为 jsonlines,然后 Athena 将能够获取所有行。