Sub topic 13
Bloom filters for equality lookups
This chapter assumes you know how row groups, column chunks, and the footer are laid out. It also assumes you know how min/max statistics let a reader skip row groups. You should be comfortable reading Python and PyArrow code.
The gap that min/max statistics leave
Min/max statistics work well when values are sorted or clustered. Suppose a column holds user IDs in random order. Every row group then has a minimum near the global minimum and a maximum near the global maximum. A filter such as user_id == 48213 falls inside every row group's range, so nothing can be skipped.
Dictionary encoding can also help here. If a column chunk is fully dictionary-encoded, a reader can check the dictionary for the value. But high-cardinality columns often fall back to plain encoding once the dictionary grows too large. A reader then has to scan the data.
A Bloom filter fills this gap for equality and IN lookups.
What a Bloom filter is
A Bloom filter is a compact bit array that answers one question: is this value in the set? It has two possible answers:
- Definitely not present. The reader can skip the row group.
- Possibly present. The reader must read the row group and check.
It never gives a false negative. It can give a false positive, which only costs an unnecessary read. Parquet stores one Bloom filter per column chunk. It uses a split-block design and hashes values with xxHash.
Where it lives in the file
The filter bytes are stored in the file, and the column chunk metadata in the footer records their offset. A reader checks the footer, finds the offset, and loads only the filter for the column it is filtering. It does this before reading any data pages.
Cost and trade-offs
A Bloom filter is extra bytes in the file. Its size depends on the number of distinct values in the column chunk and on the false positive rate you accept. A lower rate needs a bigger filter.
| Factor | Effect |
|---|---|
| More distinct values per row group | Larger filter |
| Lower false positive rate | Larger filter |
| Range filters such as `>` or `<` | No help from a Bloom filter |
| Low-cardinality column | Little benefit, since dictionary or statistics already work |
Enable Bloom filters only on columns you actually filter by equality, such as IDs, session keys, or hashes. Adding them to every column bloats the file.
Writing a file with Bloom filters
Recent PyArrow versions (21.0 and later) accept a bloom_filter_options argument in pq.write_table. Check your installed version before relying on it.
import pyarrow as pa
import pyarrow.parquet as pq
table = pa.table({
"user_id": [f"user-{i * 7919 % 1_000_003}" for i in range(1_000_000)],
"value": list(range(1_000_000)),
})
pq.write_table(
table,
"users_bloom.parquet",
row_group_size=100_000,
bloom_filter_options={"user_id": {"ndv": 100_000, "fpp": 0.01}},
)Here ndv is the expected number of distinct values per row group, and fpp is the target false positive probability. If ndv is far too low, the real false positive rate rises above fpp.
Common errors
- Expecting a speedup on range queries. Bloom filters answer only equality and
IN. - Using a reader that ignores them. Support varies by engine and version. If a query is not faster, check that your reader uses Bloom filters.
- Setting
ndvbadly. Too low gives more false positives. Too high wastes space. - Filtering on sorted columns. If min/max statistics already skip most groups, a filter adds size without benefit.
Exercise
A column of random 64-bit IDs is filtered with id == 12345. Min/max statistics skip no row groups. Which feature can skip row groups, and what are its two possible answers for each row group?
Show answer
A Bloom filter on the id column. For each row group it answers either "definitely not present", so the group is skipped, or "possibly present", so the group must be read. It never gives a false negative.
Exercise
Why would a Bloom filter not help the filter id > 950000?
Show answer
A Bloom filter only tests set membership for specific values. It cannot describe a range, so range filters rely on min/max statistics or the page index instead.