【问题标题】:Create table and query json data using Amazon Athena?使用 Amazon Athena 创建表和查询 json 数据?
【发布时间】:2017-02-22 09:54:36
【问题描述】:

我想使用 Amazon Athena 查询 JSON 格式的数据:

[{"id":"0581b7c92be",
  "key":"0581b7c92be",
  "value":{"rev":"1-ceeeecaa040"},
  "doc":{"_id":"0581b7c92be497d19e5ab51e577ada12","_rev":"1ceeeecaa04","node":"belt","DeviceId":"C001"}},
 {"id":"0581b7c92be49",
  "key":"0581b7c92be497d19e5",
  "value":{"rev":"1-ceeeecaa04031842d3ca"},
  "doc":{"_id":"0581b7c92be497","_rev":"1ceeeecaa040318","node":"belt","DeviceId":"C001"}
 }
]

【问题讨论】:

    标签: sql amazon-web-services amazon-athena


    【解决方案1】:

    Athena DDL 基于 Hive,因此您希望数组中的每个 json 对象位于单独的行中:

    {"id": "0581b7c92be", "key": "0581b7c92be", "value": {"rev": "1-ceeeecaa040"}, "doc": {"_id": "0581b7c92be497d19e5ab51e577ada12", "_rev": "1ceeeecaa04", "node": "belt", "DeviceId": "C001"} }
    {"id": "0581b7c92be49", "key": "0581b7c92be497d19e5", "value": {"rev": "1-ceeeecaa04031842d3ca"}, "doc": {"_id": "0581b7c92be497", "_rev": "1ceeeecaa040318", "node": "belt", "DeviceId": "C001"} }
    

    嵌套字段(“value”,“doc”)可能有问题,所以如果你可以扁平化 json,你会更容易。 (例如:Hive for complex nested Json

    【讨论】:

    • 我想知道如何创建表和选择操作来查询多行数据。
    • 我想如何创建表和选择操作来查询多行数据。ex:[{“_id”:“0899f824e118d390f57bc2f279bd38fe”,“_rev”:“1-81cc25723e02f50cb6fef7ce0b0f4f38”,“deviceId”: “BELT001”,“locationId”:“LID001”,“SuperviceId”:“SID001”},{“_id”:“0899f824e118d390f57bc2f279bd38fe”,“_rev”:“1-81cc25723e02f50cb6fef7ce0b0f4f38”,“deviceId”:“BELT001” ": "LID001", "SuperviceId": "SID001" }]
    • 我的意思是,在我可以帮助您之前,请检查您是否可以将您的 json 数组“分解”成多行单独的 json 对象。将您的示例转换为:
    • {"_id": "0899f824e118d390f57bc2f279bd38fe", "_rev": "1-81cc25723e02f50cb6fef7ce0b0f4f38", "deviceId": "BELT001", "locationId": "LID001", "SuperviceId:" } {“_id”:“0899f824e118d390f57bc2f279bd38fe”,“_rev”:“1-81cc25723e02f50cb6fef7ce0b0f4f38”,“deviceId”:“BELT001”,“locationId”:“LID001”,“SuperviceId”:“SID001”}
    • 感谢您的解决方案。我可以从雅典娜查询数据
    猜你喜欢
    • 2017-11-22
    • 1970-01-01
    • 1970-01-01
    • 2020-03-19
    • 1970-01-01
    • 2022-10-14
    • 2019-03-14
    • 2020-05-12
    • 1970-01-01
    相关资源
    最近更新 更多