【问题标题】:How can I get result format JSON from Athena in AWS?如何从 AWS 中的 Athena 获取结果格式 JSON?
【发布时间】:2017-10-23 00:21:25
【问题描述】:

我想从 AWS 中的 Athena 获取结果值格式 JSON。

当我从 Athena 中选择时,结果格式是这样的。

{test.value={report_1=test, report_2=normal, report_3=hard}}

有没有办法在不将“=”替换为“:”的情况下获得 JSON 格式的结果?

列格式为

map<string,map<string,string>>

【问题讨论】:

    标签: hive presto amazon-athena


    【解决方案1】:

    如果您的输入格式是 json(即您的整行是 JSON),您可以创建一个新表来保存您在 parquet、json、orc 等几个可能选项中指定的任何格式的 athena 结果。这最终会结束将查询的所有 athena 结果存储在具有所需格式的 s3 存储桶中。

    希望对你有帮助

    这是供参考的文档:https://docs.aws.amazon.com/athena/latest/ug/ctas-examples.html

    【讨论】:

      【解决方案2】:
      select  mycol
      from    mytable
      ;
      

      +--------------------------------------------------------------+
      |                            mycol                             |
      +--------------------------------------------------------------+
      | {test.value={report_3=hard, report_2=normal, report_1=test}} |
      +--------------------------------------------------------------+
      

      select  cast (mycol as json) as json
      from    mytable
      ;
      

      +--------------------------------------------------------------------------+
      |                                   json                                   |
      +--------------------------------------------------------------------------+
      | {"test.value":{"report_1":"test","report_2":"normal","report_3":"hard"}} |
      +--------------------------------------------------------------------------+
      

      【讨论】:

      • 非常感谢。我有另一个问题。当数据与字符串和地图数据混合时,我也可以将字符串数据转换为 json 格式吗?
      • 不客气。如果您有特定问题,请为此使用新帖子。附:通过在答案左侧标记V 符号来完成答案接受。另一个按钮用于投票。
      • 好的。我得到了它。谢谢。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-19
      • 2014-12-09
      • 2019-06-03
      • 2020-01-21
      • 1970-01-01
      • 2017-09-08
      相关资源
      最近更新 更多