Lesson 2 of 7 Amazon S3 Data Lakes

Choosing Data File Formats and Open Table Formats

This lesson explains how the storage format decides how much data each query reads, how well it compresses and how easily its schema can change, one of the most effective cost and performance decisions in a data lake.

Learning outcomes

After completing this lesson, you will be able to:

  • Distinguish row-based formats from columnar formats such as Parquet and ORC.
  • Explain why columnar formats are faster and cheaper to query.
  • Describe what open table formats add to plain files.
  • Choose a tool for converting formats.

The principal formats

The file format has a large effect on query speed and cost. Apache Parquet and ORC are columnar: they store each column's values together, compressed, with minimum and maximum statistics for each block. A query that needs three columns of a fifty-column table reads only those three, and it skips blocks whose statistics show they cannot match the filter. Because Athena and Redshift Spectrum charge by data scanned, this cuts cost as well as time, and it speeds up Spark.

Avro is row-based: each record is stored whole, with the schema embedded in the file, and it supports schema evolution well. That suits streaming and data exchange, where whole records are written and read one at a time. CSV and JSON are row-based text formats. They are easy to produce, so data often arrives in them, but they are slow and costly to query at scale, since every query reads every byte. The following table summarises the formats.

FormatTypeBest for
Apache Parquet, ORCColumnar, compressed, with min/max statistics per blockAnalytics: queries read only needed columns and skip blocks, cutting Athena and Spectrum cost and speeding Spark
AvroRow-based with embedded schema and schema evolutionStreaming and data exchange
CSV, JSONRow-based textRaw ingestion; slow and costly to query at scale
Sort into groups

Which file format?

Exam skills 1.2.6 · 2.4.5

Choose the file format family for each use.

Log in to try this activity Interactive activities are free with an account.

Why columnar formats are faster

Row-based formats, such as CSV and JSON, store each record's values together, which suits reading or writing whole records. Columnar formats, such as Apache Parquet and ORC, store each column's values together, which suits analytics, where queries usually read a few columns across many rows. Three effects make them faster and cheaper.

Column pruning means that a query reading 5 of 60 columns reads only those 5 columns from storage. Predicate pushdown uses the minimum and maximum values that columnar files record for each group of rows: an engine filtering on a column can skip every row group whose range cannot contain matching values. And compression is more effective, because similar values stored together, such as a column of country codes, compress much better than mixed values. Because Athena and Redshift Spectrum charge by data scanned, these effects reduce cost as well as query time.

The following diagram compares what a query reads from each layout.

What a query reads from a row-based file and from a columnar file. With JSON or CSV, every byte of every row is read. With Parquet, only the needed columns are read (column pruning), and row groups whose minimum and maximum values cannot match the filter are skipped (predicate pushdown).
Each square is one column of one row group; the layout is schematic.
Match the pairs

Why columnar is faster

Exam skills 2.4.5

Match each columnar effect with what it does.

Log in to try this activity Interactive activities are free with an account.

Open table formats

Plain Parquet files in S3 have no concept of a table transaction: updating a row means rewriting files, and a reader can see a half-finished write. Open table formats, such as Apache Iceberg, Apache Hudi and Delta Lake, add a metadata layer over Parquet files that tracks exactly which files make up the table at each point in time.

This layer provides ACID transactions, so readers always see a consistent table; row-level updates and deletes; schema evolution without rewriting data; and time travel to earlier versions. The lake then behaves like a database, an architecture often called a lakehouse, while the data files remain open Parquet that many engines, including Athena, Spark, Redshift and EMR, can read. The lesson Managing Lake Tables with Apache Iceberg and Amazon S3 Tables covers Iceberg in detail.

True or false

Open table formats

Exam skills 2.1.7

Decide whether each statement about open table formats is true.

Log in to try this activity Interactive activities are free with an account.

Converting formats

Data usually arrives as CSV or JSON and is converted to a columnar format on the way to the curated zone, and the right tool depends on how the data moves. For streaming data, Firehose record format conversion writes Parquet or ORC as it delivers, with no separate job. For batch ETL, the Glue or EMR job that cleans the data also writes it as Parquet or Iceberg. For a one-off conversion using only SQL, an Athena CREATE TABLE AS SELECT (CTAS) query reads the existing table and writes a new one in the chosen format. The following table summarises the choice.

SituationConversion
Streaming dataFirehose record format conversion to Parquet or ORC
Batch ETLGlue or EMR jobs writing Parquet or Iceberg
One-off conversion with SQLAthena CTAS
Match the pairs

Converting to columnar

Exam skills 1.2.6

Match each situation with the conversion tool.

Log in to try this activity Interactive activities are free with an account.
Worked example

What columnar storage saves

A 1 TB table of events has 60 columns, stored as JSON. A report reads five columns for one month. The following table compares the data read in each format.

FormatData read by the report
JSON (row-based text)The whole 1 TB: every row and every column must be parsed
Parquet with Snappy (about 150 GB on disk)About 12 GB: only five columns are read
Parquet, sorted by event dateLess again: row groups outside the month are skipped by their statistics

Converting once, with Firehose format conversion for new data and an Athena CTAS or Glue job for history, reduces both query cost and run time on every later query.

Check yourself

Which format suits streaming data exchange with schema evolution?

Show answer

Avro. Parquet and ORC suit analytics.

Exam Tips

Remember for the exam

  • The format for analytics is Parquet, or ORC, with compression.
  • Streaming data exchange with schema evolution suits Avro.
  • To reduce Athena costs, convert CSV and JSON into partitioned Parquet.
  • ACID updates and deletes in the lake call for Apache Iceberg.
  • To convert streaming JSON to Parquet with no code, use Firehose format conversion.