Goal
A selective query on a Parquet table reads nearly everything, or files are far bigger than expected. Before changing settings, look at what the writer actually produced. Then change the one layer that fails to skip data.
Readers skip data in this order, and each layer needs different things from the writer:
| Layer | Skips | Needs |
|---|---|---|
| Table metadata or partitions | Whole files | Partitioning, or file stats in Iceberg/Delta |
| Row group statistics | Row groups | Sorted or clustered values, usable min/max |
| Dictionary filter | Row groups | Column chunk fully dictionary-encoded |
| Bloom filter | Row groups | Bloom filter written for that column |
| Column index | Pages | Page index present, clustering inside the row group |
Clustering comes first. If every row group contains the full range of values, min/max can't skip anything, whatever the row group size.
Inspect before you tune
PyArrow: row groups, encodings and stats
import pyarrow.parquet as pq
md = pq.ParquetFile("part-00000.parquet").metadata
print(md.created_by, "rows:", md.num_rows, "row groups:", md.num_row_groups)
for rg in range(md.num_row_groups):
g = md.row_group(rg)
print(f"\nrow group {rg}: rows={g.num_rows} uncompressed={g.total_byte_size/1048576:.1f} MB")
for c in range(g.num_columns):
col = g.column(c)
s = col.statistics
rng = (s.min, s.max, s.null_count) if s and s.has_min_max else "no min/max"
print(f" {col.path_in_schema:30} {col.compression:8} "
f"{col.total_compressed_size/1048576:8.2f} MB {col.encodings} {rng}")
Read it for four things: the row group size, the columns that use most of the bytes, whether ranges overlap between row groups, and columns with no min/max.
parquet-cli
parquet meta file.parquet # row groups, encodings, sizes
parquet schema file.parquet
parquet pages -c customer_id file.parquet # page-level encodings and sizes
parquet column-index -c customer_id file.parquet
parquet column-size file.parquet # which columns cost the most
Subcommands vary by version; run parquet help.
Is Spark pushing the filter down?
EXPLAIN FORMATTED SELECT * FROM events WHERE customer_id = 42;
Look for the column in PushedFilters. Predicates wrapped in a cast or a UDF usually don't get there. Pushed means "offered to the reader", not "skipped": compare rows output by the scan with the table's total rows in the Spark UI.
Writer settings
Defaults are from parquet-java. Engines can override them.
| Property | Default | Change when |
|---|---|---|
parquet.block.size | 128 MB | Row group target. Smaller for selective reads, larger for full scans |
parquet.page.size | 1 MB | Smaller for point lookups with the column index |
parquet.page.row.count.limit | 20000 | Highly compressible columns otherwise hold too many rows per page |
parquet.dictionary.page.size | 1 MB | Dictionary falls back too early |
parquet.enable.dictionary | true | Turn off per column for near-unique values |
parquet.compression.codec.zstd.level | 3 | Raise for cold data; costs write CPU |
parquet.columnindex.truncate.length | 64 | Long strings with shared prefixes don't separate |
parquet.memory.pool.ratio | 0.95 | Rarely; see small row groups below |
parquet.writer.version | PARQUET_1_0 | Only after testing every reader |
Per-column settings use #. Pass them as Spark write options:
(df.repartitionByRange(200, "customer_id")
.sortWithinPartitions("customer_id", "event_ts")
.write
.option("compression", "zstd")
.option("parquet.block.size", str(128 * 1024 * 1024))
.option("parquet.enable.dictionary", "true")
.option("parquet.enable.dictionary#event_id", "false")
.mode("errorifexists")
.parquet("abfss://curated@account.dfs.core.windows.net/events_v2"))
For Iceberg, use table properties instead:
ALTER TABLE lake.web.events SET TBLPROPERTIES (
'write.parquet.row-group-size-bytes' = '134217728',
'write.parquet.page-size-bytes' = '1048576',
'write.parquet.dict-size-bytes' = '2097152',
'write.parquet.compression-codec' = 'zstd'
);
These affect new files only. Existing files change when compaction rewrites them.
Row groups: too small or too large
| Finding | Cause | Fix |
|---|---|---|
| Many tiny row groups in one file | Many open writers in a task, so the writer memory manager scales each one down | Repartition by the partition columns before writing |
One row group bigger than spark.sql.files.maxPartitionBytes | Row group can't be split between tasks | Lower parquet.block.size or raise the split size |
| Tasks that read zero rows | Splits that contain no row group start | Align split size with row group size |
| Executor OOM on write | Open writers x row group buffer | Fewer open writers, smaller row groups |
The row group is the unit of parallelism: a split processes the row groups whose midpoint falls inside it. A 1 GB file with one row group is one real task, however many splits Spark plans.
Dictionary fallback
Parquet starts with dictionary encoding and falls back to another encoding when the dictionary gets too large or doesn't save space. Two costs follow: larger files, and no dictionary filtering for that column chunk.
Signs of it: both RLE_DICTIONARY (or PLAIN_DICTIONARY) and PLAIN in the same column chunk's data pages. Since the dictionary page itself uses PLAIN, confirm with parquet pages rather than the footer encoding list alone.
- Medium cardinality with repeats: raise
parquet.dictionary.page.size, or write smaller row groups so each holds fewer distinct values. - Near-unique IDs: disable the dictionary for that column and save the write effort.
- Sorting by the column often fixes it, since each row group then sees fewer distinct values.
Bloom filters
Use them for equality lookups on high-cardinality columns that are not the sort key. They don't help ranges, LIKE or columns whose min/max already skips well.
(df.write
.option("parquet.bloom.filter.enabled#session_id", "true")
.option("parquet.bloom.filter.expected.ndv#session_id", "2000000")
.option("parquet.bloom.filter.fpp#session_id", "0.01")
.option("parquet.bloom.filter.max.bytes", str(4 * 1024 * 1024))
.mode("errorifexists").parquet(path))
expected.ndvis distinct values per row group, not per table.max.bytesdefaults to 1 MB. A filter too small for its NDV has a far higher false-positive rate than thefppyou set. At 1%, plan about 10 bits per value (more once sizes are rounded).- Size cost is per column per row group, so enabling it globally is expensive.
- A fully dictionary-encoded chunk can already be filtered by dictionary.
Iceberg:
ALTER TABLE lake.web.events SET TBLPROPERTIES (
'write.parquet.bloom-filter-enabled.column.session_id' = 'true',
'write.parquet.bloom-filter-max-bytes' = '4194304'
);
Statistics traps
| Trap | Effect | Fix |
|---|---|---|
INT96 timestamps (Spark's documented default) | No usable min/max, so timestamp filters skip nothing | spark.sql.parquet.outputTimestampType=TIMESTAMP_MICROS |
| Random UUID keys | Every range overlaps | Bloom filter, or cluster by another column |
| Numbers or dates stored as strings | Range compares lexically; casts block pushdown | Store proper types |
| Nested fields | Support varies by reader | Promote hot fields to top level |
aggregatePushdown on (off by default) | Fails if footer stats are missing | Enable only for known-good writers |
Warning
Changing timestamp type, writer version or codec can break older readers. Write one file and read it with every engine that consumes the table, including external ones, before rolling out.
Reader switches for diagnosis
Turn one filter off at a time to see which layer does the work. Leave them on in production.
df = (spark.read
.option("parquet.filter.columnindex.enabled", "false")
.option("parquet.filter.bloom.enabled", "false")
.option("parquet.filter.dictionary.enabled", "false")
.parquet(path))
df.where("session_id = 'abc'").write.format("noop").mode("overwrite").save()
Compare bytes read and scan output rows in the SQL tab. If disabling a layer produces wrong-result differences rather than a slower query, suspect a file written with corrupt statistics and check created_by.
Caution
Rewriting a table to apply new settings replaces files. Write to a new path, reconcile counts and sums, then swap. Never overwrite a path the same job is reading.
Prevent it next time
- Choose the sort columns from real query filters before choosing sizes.
- Add a footer check to CI: row group size, encodings and min/max on filter columns.
- Keep one shared writer profile per workload rather than settings per job.
- Re-check footers after engine upgrades, because writer defaults change.
Get the weekly HubDatAI email
One email a week with everything new: posts, learning sessions and videos. Free, no spam, unsubscribe in one click. What you get