Skip to content

Add Sbbf::insert_hashes, Sbbf::check_hashes and Sbbf::union - #11641

Draft
adriangb wants to merge 1 commit into
apache:mainfrom
adriangb:sbbf-batch-union-apis
Draft

adriangb wants to merge 1 commit into
apache:mainfrom
adriangb:sbbf-batch-union-apis

Conversation

@adriangb

@adriangb adriangb commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

DataFusion builds a parquet Sbbf as the membership test in the dynamic filter of a hash join. Each build partition fills its own filter in parallel with hashes it has already computed, the filters are merged into one, the result is folded to the target fpp, and every probe row is checked against it.

The public API cannot do this today:

Need Today
Insert or check precomputed hashes in bulk insert_hash / check_hash are private, and per hash
Merge filters built independently (one per thread or partition) Not possible
Check many hashes fast check exits early on a branch the CPU cannot predict

Measured in DataFusion on 16M probe rows: checking with a per-row branchy check takes ~104 ms, the branch-free check ~21 ms.

What changes are included in this PR?

All additions are on parquet::bloom_filter::Sbbf:

API What
insert_hashes(&mut self, &[u64]) Insert precomputed 64-bit hashes
check_hashes(&self, &[u64]) -> BooleanBuffer (feature arrow) Branch-free bulk check: tests all 8 words of the block with no early exit
union(&mut self, &Sbbf) -> Result<()> OR another filter into this one. other must have the same number of blocks or a multiple of it; a larger other is folded on the fly (same grouping as fold_to_target_fpp), so fold(a ∪ b) == fold(a) ∪ fold(b)

The hashes can come from any well-mixed 64-bit hash. check / insert keep using the spec hash; the docs say the two only agree when the caller uses the spec hash.

An earlier version of this PR added hash_value, public insert_hash / check_hash and Arrow array APIs (hash_array, insert_array, check_array, supports_data_type). DataFusion no longer needs them (it reuses its own join hashes), so they are removed.

Are these changes tested?

  • Branch-free check equals check_hash.
  • check_hashes equals check_hash for each hash.
  • Union of per-chunk filters is bit-for-bit equal to one filter of all hashes; union then fold equals fold then union; a larger filter is folded on the fly; a smaller filter cannot be unioned into a larger one.

Are there any user-facing changes?

New public API only. No breaking changes.

🤖 Generated with Claude Code

@mbutrovich

Copy link
Copy Markdown
Contributor

Can we get some extra review cycles on #11549 and land that first, since it already brings in Sbbf?

adriangb added a commit to adriangb/datafusion that referenced this pull request Oct 17, 2026
Pointing at arrow-rs main pulled in unrelated behavior changes (interleave
buffer sharing, DST handling). Use a branch with the 60.0.0 tag, apache#11088 and
the commits of apache/arrow-rs#11641 instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@adriangb
adriangb force-pushed the sbbf-batch-union-apis branch from 2f6464e to 77292ad Compare October 18, 2026 04:37
adriangb added a commit to adriangb/datafusion that referenced this pull request Oct 18, 2026
Points the arrow-rs crates at adriangb/arrow-rs sbbf-batch-union-apis-60:
arrow-rs 60.0.0 + apache/arrow-rs#11088 + the commit of
apache/arrow-rs#11641. Remove once arrow-rs releases these APIs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@adriangb adriangb changed the title Add Sbbf hash, sharded insert and Arrow array batch APIs Add Sbbf hash and Arrow array batch APIs Oct 18, 2026
@adriangb

Copy link
Copy Markdown
Contributor Author

Thanks @mbutrovich . I reviewed #11549 and plan to restack this work on it once it merges (experiment for that in #11685)

@mbutrovich

Copy link
Copy Markdown
Contributor

Thanks @mbutrovich . I reviewed #11549 and plan to restack this work on it once it merges (experiment for that in #11685)

Sounds good, thanks for the review pass! I was excited to see someone with another use for it so wanted to make sure it lands with what you need.

adriangb added a commit to adriangb/datafusion that referenced this pull request Oct 20, 2026
Points the arrow-rs crates at adriangb/arrow-rs sbbf-batch-union-apis-60:
arrow-rs 60.0.0 + apache/arrow-rs#11088 + the commit of
apache/arrow-rs#11641. Remove once arrow-rs releases these APIs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
adriangb added a commit to adriangb/datafusion that referenced this pull request Oct 30, 2026
Each build partition now fills its own Sbbf from the join hashes
(HASH_JOIN_SEED, the same hashes the probe side computes) in its build
task, sized for its distinct key count times the number of partitions.
At the barrier the partition filters are ORed with Sbbf::union, folded
to the target fpp, and dropped if they still exceed it. The probe checks
a whole batch with the branch-free Sbbf::check_hashes.

This removes the sort/dedup step, the serial fill at the barrier and the
per-column filters, and gives float keys a bloom filter too.
hash_join_bloom_filter_max_bytes now defaults to 8 MiB: larger filters
fall out of cache and were slower in TPC-H SF100 benchmarks.

Bumps the arrow-rs pin for Sbbf::insert_hashes / union / check_hashes
(apache/arrow-rs#11641).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@adriangb adriangb changed the title Add Sbbf hash and Arrow array batch APIs Add Sbbf::insert_hashes, Sbbf::check_hashes and Sbbf::union Oct 30, 2026
@adriangb
adriangb force-pushed the sbbf-batch-union-apis branch from adfd09f to f929d5c Compare November 2, 2026 19:06
@etseidl

etseidl commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

@adriangb do you want to dust this one off? I think we're close to the point of pulling bloom filters into a new crate.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@adriangb
adriangb force-pushed the sbbf-batch-union-apis branch from f929d5c to d2a52f9 Compare November 10, 2026 18:26
@adriangb

Copy link
Copy Markdown
Contributor Author

I've rebased. I can't mark this as ready / non-draft because I've hit my PR limit.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

parquet Changes to the parquet crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants