About Skills Projects Blog Contact View my CV ↗ Español
Parquet deep dive: a hands-on guide to the format behind the modern data stack

Parquet deep dive: a hands-on guide to the format behind the modern data stack

Hands-on Parquet guide: row groups, compression, partitions, metadata, Polars, DuckDB, and how to read large files with real speed.

By Omar Flores
Table of Contents

Imagine you store your application logs in CSV. One million lines, 400 MB. To answer “how many errors per service yesterday?”, the engine has to read all 400 MB, parse every line, convert dates and numbers, and discard almost everything. It takes 40 seconds and consumes 2 GB of RAM.

The same data in Parquet takes 40 MB. The same query reads only the timestamp, service, and level columns, skips blocks that do not belong to “yesterday,” and responds in 200 milliseconds with 100 MB of RAM. The engine did not change. The format did.

Parquet is the format that makes the modern stack possible: lakehouse, DuckDB, Polars, ClickHouse, Spark, Athena, BigQuery. Understanding how it works internally lets you stop guessing why a query is slow and start designing files that read fast.


What Parquet is and why it is fast

Parquet is a columnar file format: it stores values grouped by column, not by row. That has three direct consequences:

  1. You read only the columns you need. If your table has 50 columns and you query 3, the engine does not touch the other 47.
  2. You compress better. Values in the same column resemble each other; compression algorithms exploit that redundancy.
  3. You can skip blocks. Parquet stores statistics per block (min, max, nulls) and the engine uses them to discard data without reading it.

Compared to CSV:

Aspect CSV Parquet
Orientation Rows Columns
Types Text, must infer Typed schema
Compression Low (text) High (columnar + codec)
Statistics No Yes, per row group
Selective reads No Yes, projection pushdown
Typical size 5-10x Reference

Parquet is not a database: it is a file. It has no transactions, no row-by-row updates, no concurrency guarantees. For that there are table formats like Iceberg or Delta, which use Parquet underneath.


Anatomy of a Parquet file

A Parquet file has four levels:

file.parquet
├── schema (columns and types)
├── row group 0
│   ├── column chunk: timestamp
│   │   ├── page 0
│   │   └── page 1
│   ├── column chunk: service
│   └── column chunk: level
├── row group 1
│   └── ...
└── footer (metadata: schema, statistics, offsets)
  • Row group: a horizontal block of rows (typically 100k-1M rows). It is the unit of parallelism and pruning.
  • Column chunk: the data of one column inside a row group. Compression lives here.
  • Page: the minimum read/write unit inside a column chunk.
  • Footer: the file index. It contains the schema, the location of each row group, and statistics.

The footer is the key: a reader can open a 10 GB file, read the footer (a few KB), and know exactly which row groups it needs without touching the data. That is what makes a filtered query fast.


Hands-on: write and read with Polars

Create a DataFrame and write it

import polars as pl

df = pl.DataFrame({
    "timestamp": ["2026-12-05T10:00:00Z", "2026-12-05T10:01:00Z", "2026-12-05T10:02:00Z"],
    "service": ["api", "api", "worker"],
    "level": ["INFO", "ERROR", "ERROR"],
    "duration_ms": [120, 1834, 45],
})

df.write_parquet(
    "logs.parquet",
    compression="zstd",
    row_group_size=100_000,
)

row_group_size controls how many rows go into each row group. A value of 100k-500k is usually a good balance: enough to compress well, not so much that it limits pruning.

Read only what is needed

lf = pl.scan_parquet("logs.parquet")

result = (
    lf.select("timestamp", "service", "level", "duration_ms")
    .filter(pl.col("level") == "ERROR")
    .group_by("service")
    .agg(pl.len().alias("errors"))
    .collect(engine="streaming")
)
print(result)

scan_parquet does not load the file: it builds a plan. select and filter are applied before materializing. If the file is sorted by level, the engine can skip entire row groups.

See the plan

print(
    pl.scan_parquet("logs.parquet")
    .filter(pl.col("level") == "ERROR")
    .select("service")
    .explain()
)

Look for SELECTION and PROJECT in the output to confirm the filter and projection were applied at scan time.


Hands-on: query with DuckDB

DuckDB reads Parquet directly, regardless of the file:

import duckdb

result = duckdb.sql("""
    SELECT service, count(*) AS errors
    FROM read_parquet('logs.parquet')
    WHERE level = 'ERROR'
    GROUP BY service
    ORDER BY errors DESC
""").df()
print(result)

To see what the engine is doing:

EXPLAIN ANALYZE
SELECT service, count(*) AS errors
FROM read_parquet('logs.parquet')
WHERE level = 'ERROR'
GROUP BY service;

The output shows the PARQUET_SCAN operator with projected columns and the applied filter. If you see PROJECTION with fewer columns than the file has, pushdown worked.

Read from S3

INSTALL httpfs;
LOAD httpfs;

SELECT service, count(*) AS errors
FROM read_parquet('s3://logs/date=2026-12-05/*.parquet')
WHERE level = 'ERROR'
GROUP BY service;

DuckDB downloads only the necessary columns and row groups. If partitions are in the path (date=...), the date filter can discard entire files.


Inspect metadata without reading data

With PyArrow

import pyarrow.parquet as pq

pf = pq.ParquetFile("logs.parquet")

print(pf.metadata)
print("Rows:", pf.metadata.num_rows)
print("Row groups:", pf.metadata.num_row_groups)
print("Columns:", pf.schema.names)

for i in range(pf.metadata.num_row_groups):
    rg = pf.metadata.row_group(i)
    print(f"Row group {i}: {rg.num_rows} rows, {rg.total_byte_size} bytes")

With DuckDB

SELECT *
FROM parquet_metadata('logs.parquet')
LIMIT 20;

SELECT *
FROM parquet_schema('logs.parquet');

parquet_metadata gives you, per row group and column: number of values, compressed size, uncompressed size, encoding, and statistics (min/max). It is the fastest way to diagnose why a query is not pruning.


Compression and sizes: what to choose

Parquet supports several codecs:

  • Zstd: the best compression/speed balance for analytics. Recommended by default.
  • Snappy: faster to decompress, compresses less. Useful if CPU is the bottleneck.
  • Gzip: compresses well, but is slow. Avoid it for interactive queries.
  • LZ4: fast, moderate compression.
df.write_parquet("data.parquet", compression="zstd")
df.write_parquet("data.parquet", compression="snappy")

The rule: Zstd for data that is queried a lot; Snappy if decompression is the bottleneck; Gzip only for cold archive.

File size

  • < 10 MB: too many small files; metadata overhead and listing/opening latency dominate.
  • 100-500 MB: the ideal range for most cases.
  • > 1 GB: less parallelism and worse pruning; consider repartitioning.

If your pipeline generates thousands of 1 MB files, the problem is not Parquet: it is the write strategy. Compact with a periodic task.


Partitioning and sorting: where speed is won

Partition by low-cardinality columns

logs/
  date=2026-12-05/
    service=api/
      part-000.parquet
    service=worker/
      part-000.parquet
  date=2026-12-06/
    ...

A query for one day and one service reads a fraction of the dataset. Do not partition by user_id or trace_id: you would create millions of folders.

Sort by the column you filter most

df.sort("timestamp").write_parquet(
    "logs.parquet",
    compression="zstd",
    row_group_size=100_000,
)

With files sorted by timestamp, row groups have disjoint ranges and the engine can discard most of them.

Avoid the small file problem

If you write one file per event, you will have millions of tiny files. Group into time windows (1 minute, 5 minutes) or compact periodically.


Real-world scenarios

Application logs

  • Store in Parquet by date and service.
  • Sort by timestamp.
  • Use wide events with typed columns (level, duration_ms, trace_id).
  • Query with DuckDB for historical analysis and ClickHouse for real time.

Business events

  • Partition by date and event_type.
  • Keep an ingested_at column for auditing.
  • Convert dates to Datetime with explicit timezone.

Data lake / lakehouse

  • Parquet is the file format; Iceberg/Delta add transactions and schema evolution.
  • Do not write directly to a directory if you need concurrency; use a table format.

Export from Excel or a database

  • Extract once to Parquet, then analyze with DuckDB/Polars.
  • Avoid going back to Excel for every iteration.

ML features

  • Parquet stores typed, compressed features.
  • For embeddings, consider Lance or a vector format; Parquet is not ideal for similarity search.

Common mistakes and when NOT to use Parquet

Mistakes

  1. Convert to Parquet once and go back to CSV. You lose all the benefit.
  2. One giant 50 GB file. Better several 100-500 MB files.
  3. Millions of 1 MB files. Compact.
  4. Partition by high cardinality. Millions of folders and metadata.
  5. Not sorting by the filter column. Pruning will not help.
  6. Using Gzip for interactive queries. Decompression dominates.
  7. Confusing null with NaN. Parquet distinguishes them; your logic should too.
  8. Ignoring schema drift. A file with a new column breaks reading if you do not use schema evolution.

When NOT to use Parquet

  • Frequent row-by-row updates. Parquet is immutable; you rewrite files.
  • Concurrent transactions. You need a table format or a database.
  • Very small files. Overhead outweighs the benefit.
  • Data that is read only once. Conversion cost may not amortize.
  • Vector similarity search. Use a vector index or Lance.

Checklist and recipes

Write well

  • Parquet format, not CSV.
  • Zstd compression.
  • Row groups of 100k-500k rows.
  • Files of 100-500 MB.
  • Partition by date and service (low cardinality).
  • Sort by the column most often filtered.
  • Explicit schema, no inference.
  • Stable column names.

Read fast

  • scan_parquet instead of read_parquet if there are more than two operations.
  • select only the necessary columns.
  • filter early.
  • collect(engine="streaming") for data that does not fit.
  • EXPLAIN / EXPLAIN ANALYZE to verify pushdown.
  • Check parquet_metadata if pruning is not working.

Diagnosis

-- How many row groups does the file have?
SELECT count(*) FROM parquet_metadata('data.parquet');

-- Which columns are being read?
EXPLAIN ANALYZE SELECT service FROM read_parquet('data.parquet') WHERE level = 'ERROR';

-- How much does each column weigh?
SELECT column_name, sum(total_compressed_size) AS bytes
FROM parquet_metadata('data.parquet')
GROUP BY column_name
ORDER BY bytes DESC;

Parquet does not make you a better analyst. It removes the cost of reading what you do not need. And when you stop reading what you do not need, analysis stops being a wait and starts being a conversation.