Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I Configure file format of AWS Athena results

Currently, the Athena query results are in tsv format in S3. Is there any way to configure Athena queries to return results in Parquet format.

like image 950
Saisumanth Gopisetty Avatar asked Oct 11 '18 14:10

Saisumanth Gopisetty


People also ask

Which is the format of the output results of Athena queries?

CSV is the only output format used by the Athena SELECT query, but you can use UNLOAD to write the output of a SELECT query to the formats that UNLOAD supports. Although you can use the CTAS statement to output data in formats other than CSV, those statements also require the creation of a table in Athena.

What file formats does Athena support?

Amazon Athena supports a wide variety of data formats like CSV, TSV, JSON, or Textfiles and also supports open source columnar formats such as Apache ORC and Apache Parquet. Athena also supports compressed data in Snappy, Zlib, LZO, and GZIP formats.

Where are Athena results stored?

Amazon Athena is a interactive query service that makes it easy to analyze data directly in Amazon S3 using standard SQL. Athena stores all the query result in an S3 bucket.


1 Answers

Answer

At this moment it isn't possible to do it directly with Athena. When it comes to configure result of the Athena query you can only setup query result location and encryption configuration.

Workaround

1) From October Athena supports CTAS query, you can try to use this feature.

https://docs.aws.amazon.com/athena/latest/ug/ctas.html

https://docs.aws.amazon.com/athena/latest/ug/ctas-examples.html

I think example 4 or 5 may interest you.

2) You can create Python script and use Boto3 framework. Here is the example, you can adapt this script to your requirements and add saving query results to the parquet format.

https://gist.github.com/schledererj/b2e2a800998d61af2bbdd1cd50e08b76

3) If you want to transform your data you should use rather such services as AWS EMR or AWS Glue.

like image 151
j.b.gorski Avatar answered Sep 30 '22 06:09

j.b.gorski