Past the 1 MiB dictionary page limit a Parquet column silently falls back to plain. A pyarrow probe measures the size cost and shows how to detect it.
A column that stops being dictionary encoded
Dictionary encoding is one of the reasons Parquet files are small. A writer collects the distinct values of a column into a dictionary page and replaces each value in the data pages with a short integer index into it. A column of a million ISBNs drawn from a thousand distinct books stores a thousand strings and a million small integers, and the integers compress extremely well.
The dictionary has a size limit. The Parquet format specification describes what happens when it is reached: if the dictionary grows too big, whether in size or number of distinct values, the encoding falls back to the plain encoding. The writer keeps the dictionary it has built for the pages already written and writes the remaining values of that column chunk as plain values. Nothing fails, no warning appears, and the file is still valid. It is simply much larger than it would have been, and readers lose the dictionary-based optimisations some engines apply to filters and grouping.
This guide measures the fallback with pyarrow, shows how to detect it, and explains what to change in pyarrow and in Spark, which writes Parquet through parquet-java.
Worked example: an ISBN column at three cardinalities
The probe writes a single string column of one million rows, each value an 18-character code like ISBN-0000000004711, at three different numbers of distinct values. Each file is written four ways with pyarrow 26.0.1: the defaults, dictionary encoding turned off, a 16 MiB dictionary page limit instead of the default 1 MiB, and the defaults with 100,000-row row groups instead of one row group. Snappy compression, pyarrow's default, applies throughout. The data is synthetic.
| Distinct values | Defaults | Dictionary off | 16 MiB dictionary limit | 100k-row groups |
|---|---|---|---|---|
| 1,000 | 151,298 B | 2,468,697 B | 151,298 B | 198,807 B |
| 50,000 | 6,632,362 B | 6,537,237 B | 2,330,541 B | 7,479,123 B |
| 400,000 | 7,019,241 B | 6,927,405 B | 5,088,298 B | 7,866,260 B |
With 1,000 distinct values the dictionary is about 5 KB after compression and the file is sixteen times smaller than without a dictionary. With 50,000 distinct values the raw dictionary would hold about a megabyte of strings, slightly over the 1 MiB default limit. The writer falls back, and the file is larger than if dictionary encoding had never been tried, because it carries the partial dictionary plus plain-encoded values. Raising the limit to 16 MiB lets the whole dictionary fit, and the file shrinks to 35% of the default size.
At 400,000 distinct values, the larger limit still helps, from 7.0 MB to 5.1 MB, but less: the dictionary itself is now 2.8 MB compressed. At this cardinality the dictionary stops paying for itself quickly, and whether to raise the limit depends on how readers use the column.
Smaller row groups did not help in this data. Each 100,000-row group of the 50,000-value column still contains all 50,000 values, because the probe's values cycle through the whole range, so every row group fell back and also paid for its own dictionary page. In data where values cluster by time or by key, smaller row groups can keep each dictionary under the limit; in uniformly spread data they cannot.
Detecting fallback
The obvious check does not work. Column chunk metadata lists the encodings used in the chunk, and for every dictionary-encoded column in this probe, fallen back or not, pyarrow reported the same list: PLAIN, RLE, RLE_DICTIONARY. The dictionary page itself is written with the plain encoding, so PLAIN appears even when no data page fell back. The list cannot tell you whether fallback happened.
What does tell you is size. Write a sample of the column with dictionary encoding on and off and compare, or compare the column chunk's compressed size against the compressed size of its dictionary page.
import os, tempfile
import pyarrow as pa
import pyarrow.parquet as pq
def column_bytes(table, **options):
path = os.path.join(tempfile.gettempdir(), "fallback_check.parquet")
pq.write_table(table, path, **options)
md = pq.ParquetFile(path).metadata
return sum(md.row_group(i).column(0).total_compressed_size for i in range(md.num_row_groups))
def dictionary_report(values):
t = pa.table({"v": pa.array(values)})
on, off = column_bytes(t), column_bytes(t, use_dictionary=False)
big = column_bytes(t, dictionary_pagesize_limit=16 * 1024 * 1024)
return {"default": on, "no_dictionary": off, "16MiB_limit": big,
"suspect_fallback": on > 0.8 * off and big < 0.8 * on}
values = [f"ISBN-{(i * 7919) % 50_000:013d}" for i in range(200_000)]
print(dictionary_report(values))
# pyarrow 26.0.1: default 1,401,538 B, no dictionary 1,307,368 B, 16 MiB limit 725,172 B, suspect_fallback TrueThe 0.8 thresholds are a heuristic for flagging columns to look at, not a rule from the format. A column where the default size is close to the no-dictionary size, but a larger limit shrinks it substantially, is almost certainly falling back.
The settings that control it
In pyarrow, write_table and ParquetWriter take dictionary_pagesize_limit. Its documentation gives the default as 1 MB and says that if the dictionary size is too large, the column falls back to plain. use_dictionary can be a boolean or a list of column names, so you can turn dictionary encoding off for columns where it never helps, such as unique identifiers, and keep it for the rest.
In Spark and other writers built on parquet-java, the corresponding Hadoop configuration properties are parquet.dictionary.page.size, which defaults to 1 MB in parquet-java's ParquetProperties, and parquet.enable.dictionary. They can be set on the Spark session's Hadoop configuration or passed as write options.
# PySpark: raise the dictionary page limit for one write
(df.write
.option("parquet.dictionary.page.size", str(16 * 1024 * 1024))
.mode("overwrite")
.parquet("s3://example-bucket/orders/"))Treat the Spark snippet as a pattern to verify on your own cluster: check the written files with the size comparison above rather than assuming the option reached the writer.
Checking files that already exist
You do not need to rewrite data to find affected columns. Parquet footers record, for every column chunk, its compressed size, its row count through the row group, and whether a dictionary page is present with its offset. Reading only the footers of a day's files gives you bytes per row for each column, which is cheap even across thousands of files. A string column whose bytes per row jumps between two days, with no change in the value width, is the signature to look for. Then take a sample of that day's values and run the size comparison to confirm the cause.
Keep the results as a small time series per table and column. Fallback is a threshold effect, so the useful signal is the step, not the absolute size. When a column steps up and stays up, either raise the limit for that column's writer or decide that the column has become effectively unique and turn dictionary encoding off for it.
Tradeoffs of a larger limit
- Writer memory. The writer holds the dictionary for each column chunk in memory while it writes. A 16 MiB limit across many string columns and many concurrent tasks adds up.
- Reader memory. Readers load the dictionary page before decoding a column chunk. Very large dictionaries make the first access to each chunk more expensive.
- Diminishing returns. As the 400,000-value case shows, when most values are distinct the dictionary is nearly as large as the data. For truly unique columns, turning dictionary encoding off is cleaner than raising the limit.
- Compression does part of the work anyway. General-purpose compression of plain values recovers some of the repetition. The gap between dictionary and plain shrinks with stronger codecs; measure with the codec you use.
Failure modes
- Silent growth. A column's cardinality creeps past the limit as the business grows, and storage and scan costs jump with no code change. Track bytes per row per column over time.
- Different behaviour per file. Because the limit applies per column chunk, files from a day with more distinct values fall back while files from quieter days do not. Query performance varies by partition for no visible reason.
- Trusting the encodings list. As shown above, it reports
PLAINfor both healthy and fallen-back columns.
Verification
For each large string column, run the size comparison on a representative sample monthly, or whenever a table's cardinality changes noticeably. Record the default, no-dictionary and larger-limit sizes. If the default is close to no-dictionary and the larger limit is much smaller, the column is falling back and the limit is worth raising. If all three are close, the column is effectively unique and dictionary encoding can be turned off for it.
Primary references: the Apache Parquet format specification, encodings section on dictionary encoding; the pyarrow pyarrow.parquet.write_table documentation for use_dictionary and dictionary_pagesize_limit; and ParquetProperties and ParquetOutputFormat in the parquet-java repository.