问题
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