Skip to content

Data engineering basics · Part 6 of 10

Parquet, CSV and partitioning: storing data so queries stay cheap

Columnar formats like Parquet and sensible partitioning let a query read only the data it needs. See why they beat CSV and JSON for analytics.

· 2 min read

data-engineeringparquet

How you lay files out on disk decides how much data every query must read, and in cloud warehouses and lakes that is directly what you pay for.

Row formats and column formats

CSV and JSON are row-oriented text. To compute the average of one column, a reader still has to parse every field of every row. They carry no types, so "007" and 7 are only distinguished by convention.

Parquet and ORC are columnar and binary. Values of one column are stored together, compressed and typed. A query that needs two columns out of fifty reads only those two, and min and max statistics in the file let it skip whole chunks.

Compression and size

Similar values sit next to each other in a column, so compression works very well. The same table is often several times smaller in Parquet than in CSV, which means less storage and less data to scan.

Partitioning

Partitioning splits a table into folders by the value of a column, most often the date.

shell
events/year=2026/month=01/day=15/part-0000.parquet
events/year=2026/month=01/day=16/part-0000.parquet

A query with WHERE day = '2026-01-15' reads one folder and ignores the rest. This is called partition pruning.

Choosing the partition column

  • Pick a column that queries filter on almost every time, usually an event date.
  • Keep cardinality moderate. Partitioning by user id creates millions of tiny folders.
  • A common rule of thumb is files of roughly 100 MB to 1 GB, though the best size depends on your engine. Thousands of tiny files make listing and opening them slower than reading the data.
Python
import csv

def sum_column(path, name):
    # A CSV reader must parse every field of every row, even though we only use one column.
    with open(path, newline="") as handle:
        return sum(float(row[name]) for row in csv.DictReader(handle))

Takeaway

Use a columnar format with types for anything analysed repeatedly, partition by the column you filter on most, and keep files a sensible size. Keep CSV for exchange with people and for small inputs.

A knowledge article, drafted with AI assistance and checked with automated tests. It is general background, not a description of my own experience or of any client's work.

Comments

Leave a comment

No account or email needed. Comments appear after review. A one-way hash of your IP address is kept for 30 days to fight spam, then erased.