如何从 AWS 中的 Athena 获取结果格式 JSON?
How can I get result format JSON from Athena in AWS?
我想从 AWS 中的 Athena 获取结果值格式 JSON。
当我select从雅典娜然后结果格式是这样的。
{test.value={report_1=test, report_2=normal, report_3=hard}}
有什么方法可以在不将“=”替换为“:”的情况下获得 JSON 格式的结果吗?
列格式为
map<string,map<string,string>>
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(即您的整行是 JSON),您可以创建一个新的 table 来保存您指定的几种可能格式中的任何格式的 athena 结果parquet、json、orc 等选项。这最终会将查询的所有 athena 结果存储在具有所需格式的 s3 存储桶中。
希望这对您有所帮助
参考文档如下:https://docs.aws.amazon.com/athena/latest/ug/ctas-examples.html
我想从 AWS 中的 Athena 获取结果值格式 JSON。
当我select从雅典娜然后结果格式是这样的。
{test.value={report_1=test, report_2=normal, report_3=hard}}
有什么方法可以在不将“=”替换为“:”的情况下获得 JSON 格式的结果吗?
列格式为
map<string,map<string,string>>
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(即您的整行是 JSON),您可以创建一个新的 table 来保存您指定的几种可能格式中的任何格式的 athena 结果parquet、json、orc 等选项。这最终会将查询的所有 athena 结果存储在具有所需格式的 s3 存储桶中。
希望这对您有所帮助
参考文档如下:https://docs.aws.amazon.com/athena/latest/ug/ctas-examples.html