使用 Athena 查询将字符串更改为表格格式

问题描述 投票:0回答:1

我有这个 JSON 文件

{"Item":{"author":{"S":"John"},"title":{"S":"Page A"},"mytext":{"S":"This is sample text"}}}
{"Item":{"author":{"S":"Ram"},"title":{"S":"Page B"},"mytext":{"S":"Another book text"}}}

我在 Athena 中创建了一个表:

CREATE EXTERNAL TABLE financials_raw_json (
  Item string
)
ROW FORMAT SERDE 'org.openx.data.jsonserde.JsonSerDe'
LOCATION 's3://lambdaoks/AWSDynamoDB/016/data/' 

我得到字符串形式的结果。这是预期的且正确的。

但是有可能得到表格结果吗?例如

author  title   mytext
John    Page A  This is sample text
Ram Page B  Another book text
amazon-web-services amazon-dynamodb amazon-athena
1个回答
0
投票

为什么要尝试分解字符串而不是创建 DynamoDB 中存在的表?

CREATE EXTERNAL TABLE IF NOT EXISTS financials_raw_json (
  Item struct <author:struct<S:string>,
               title:struct<S:string>,
               myText:struct<S:string>>
)
ROW FORMAT SERDE 'org.openx.data.jsonserde.JsonSerDe'
LOCATION LOCATION 's3://lambdaoks/AWSDynamoDB/016/data/'

如果您不想手动创建表,您可以使用 JSON 分类器在其上运行 Glue 爬虫,这将自动为您提供相同的输出。

© www.soinside.com 2019 - 2024. All rights reserved.