AWS Builder Center
From CSV to Parquet in Amazon Athena with One Query

From CSV to Parquet in Amazon Athena with One Query

How to Cut Data Scan Costs and Accelerate Cloud Analytics Without Building Complex Pipelines

When you start analyzing data on AWS, the standard workflow feels intuitive: create an Amazon S3 bucket, upload raw  .csv  files, and point Amazon Athena to them so you can run familiar SQL queries.
It works instantly. But here is the catch that catches many beginners by surprise: Athena does not bill for the compute time of your query; it bills for the volume of data scanned.
Every time you execute a  SELECT  on a raw CSV, Athena has to scan every single row and every single column across the entire file. A quick test query on a local dataset is negligible, but querying messy, uncompressed files repeatedly is the fastest way to burn through your budget.
The fix isn't to build a heavy data pipeline. You can convert your data into partitioned, compressed Apache Parquet format in place, using a single SQL query.

Why Parquet + Partitioning Matters

  • Columnar Storage: Unlike CSV (row-based), Parquet stores data column-by-column. If your query only asks for  SELECT sum(amount) , Athena reads only the  amount  column, skipping the rest of the dataset.
  • Compression & Partitioning: Dividing files into logical folders (like  /country=AR/ ) lets Athena skip entire folders if your query filters by that criterion. Less data scanned means queries run faster and cost a fraction of a cent.

The 3-Step Setup

Step 1: Point Athena to the Raw CSV

Upload your files to an S3 path (e.g.,  s3://your-bucket/sales/csv/ ). Create the external schema in Athena:

CREATE DATABASE IF NOT EXISTS demo;
CREATE EXTERNAL TABLE demo.sales_csv (
order_id string,
order_date date,
country string,
amount double
)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY ','
LOCATION 's3://your-bucket/sales/csv/'
TBLPROPERTIES ('skip.header.line.count'='1');

(Ensure dates follow the  YYYY-MM-DD  format. If your text values contain commas inside quotes, use  OpenCSVSerDe  instead).

Step 2: Transform and Partition with a Single CTAS Query

Instead of writing an ETL script or provisioning external jobs, use a CTAS statement ( CREATE TABLE ... AS SELECT ). It defines the optimized table and loads the data simultaneously:

CREATE TABLE demo.sales_parquet
WITH (
format = 'PARQUET',
external_location = 's3://your-bucket/sales/parquet/',
partitioned_by = ARRAY['country']
) AS
SELECT
order_id,
order_date,
amount,
country
FROM demo.sales_csv;


Step 3: Compare the Numbers Run a filtered query on both tables:

SELECT sum(amount)
FROM demo.sales_parquet
WHERE country = 'AR';

Look at the "Data scanned" metric in your query execution details. The Parquet version skips the non-matching country directories and reads only the requested columns, dropping your scanned byte count dramatically.

Gotchas to Keep in Mind

  • The 100-Partition Limit: A single CTAS execution can write a maximum of 100 partitions. If your column has high cardinality (like postal codes or specific timestamps), batch them with  INSERT INTO  instead of CTAS.
  • Static Snapshot: CTAS does not automatically sync incoming data. When new CSV files land in S3, you will need an incremental  INSERT INTO  statement or an automated catalog sync.
Building efficient architectures on the cloud doesn't always require orchestrating complex services; sometimes, it’s just about choosing the right storage format on Day 1.




Over to the community: When you need to optimize ad-hoc analytical queries on S3, do you stick with quick CTAS queries in Athena, or do you automate the conversion upstream using AWS Glue? Let’s discuss below! 💜
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article