How can I get result format JSON from Athena in AWS?

白昼怎懂夜的黑 提交于 2021-02-19 03:18:58

问题


I want to get result value format JSON from Athena in AWS.

When I select from the Athena then the result format like this.

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

Is there any way to get JSON format result without replacing "=" to ":" ?

The column format is

map<string,map<string,string>>

回答1:


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"}} |
+--------------------------------------------------------------------------+



回答2:


If your input format is json (i.e. your whole row is JSON) you can create a new table that holds athena results in whatever format you specify out of several possible options like parquet, json, orc etc. This would ultimately end up storing all athena results of your query, in an s3 bucket with the desired format.

hope this helps

here's the documentation for reference: https://docs.aws.amazon.com/athena/latest/ug/ctas-examples.html



来源:https://stackoverflow.com/questions/44128172/how-can-i-get-result-format-json-from-athena-in-aws

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!