如何在aws中从athena获取结果格式json?

e0bqpujr  于 2021-06-26  发布在  Hive
关注(0)|答案(2)|浏览(345)

我想从aws中的athena获取结果值格式json。
当我从雅典娜中选择时,结果格式如下。

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

有没有办法不替换“=”to“:”就得到json格式的结果?
列格式为

map<string,map<string,string>>
llmtgqce

llmtgqce1#

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

os8fio9y2#

如果您的输入格式是json(即整行都是json),那么您可以创建一个新表,该表以您指定的任何格式保存athena结果,其中包括几个可能的选项,如parquet、json、orc等。这最终会将查询的所有athena结果以所需格式存储在s3存储桶中。
希望这有帮助
以下是供参考的文档:https://docs.aws.amazon.com/athena/latest/ug/ctas-examples.html

相关问题