Skip to content

Add groupBloomFilter aggregate function and bloomFilterContains scalar function - #101841

Open
otselnik wants to merge 153 commits into
ClickHouse:masterfrom
otselnik:bloom
Open

otselnik wants to merge 153 commits into
ClickHouse:masterfrom
otselnik:bloom

Conversation

@otselnik

@otselnik otselnik commented Apr 6, 2026 •

Copy link
Copy Markdown
Contributor

Adds the groupBloomFilter aggregate function and the bloomFilterContains scalar function for memory-efficient probabilistic set-membership testing. This can be used to detect new values, perform approximate deduplication checks, and compare large datasets without materializing exact sets.

Related: #11700

Changelog category (leave one):

  • New Feature

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Add the groupBloomFilter aggregate function for building mergeable Bloom filter states and the bloomFilterContains scalar function for testing whether values are probably present. Bloom filter sizing can be configured using an expected element count and false-positive rate or directly using the filter size and number of hashes, with an optional seed. The states support the -State and -MergeState combinators and can be stored in AggregatingMergeTree. Numeric probes, including Decimal, are converted to the filter's value type using accurate casts.


Workflow [PR]
Sync PR [sync-upstream/pr/101841]

otselnik added 2 commits April 3, 2026 18:25
…r function

Implement a probabilistic Bloom filter as an aggregate function groupBloomFilter
that builds a filter from column values, and a scalar function bloomFilterContains
that checks membership in the filter.

Features:
- Support for all numeric types (UInt8-UInt256, Int8-Int256, Float32/64)
- Support for Date, Date32, DateTime, DateTime64, UUID, IPv4, IPv6, Enum8, Enum16
- Support for String and FixedString types
- Configurable parameters: expected_elements, false_positive_rate, seed
- Alternative parameter form: filter_size_bytes, num_hashes, seed
- Default parameters when none specified
- State storage in AggregatingMergeTree via -State combinator
- Merge support with compatibility checks
- Documentation for both functions

Tests split into separate files:
- Basic functionality and data types
- Parameters and validation
- Merge and boundary conditions
- AggregatingMergeTree storage
- Use cases with const/non-const arguments
alexey-milovidov and others added 7 commits May 24, 2026 01:22
`aspell-dict.txt` was deleted in master along with the `aspell` and
`codespell` style checks. Removing the file here so the PR can merge
cleanly without a modify/delete conflict.
# Conflicts:
#	src/AggregateFunctions/registerAggregateFunctions.cpp
@alesapin alesapin added the can be tested Allows running workflows for external contributors label Jun 22, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jun 22, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [fec0b3c]

Summary: ✅


AI Review

Summary

This PR adds groupBloomFilter states and bloomFilterContains for probabilistic membership checks, including storage, merging, and numeric probe conversion. Two conversion defects remain: Bool filters deterministically alias unrelated numeric probes, and overflowing Decimal probes abort queries instead of returning absent.

Missing context / blind spots
  • ⚠️ No built ClickHouse binary is available locally, so the complete scalar reproductions were not executed against the PR. The underlying cast behaviors were reproduced on the public test server (26.10.3.7) and traced through the current source. All changed local files match PR head fec0b3c6eeb01113bb59e1cbc8392caeff6d4b2c. The latest CI workflow was still running when inspected.
Findings

❌ Blockers

  • src/Functions/FunctionsBloomFilter.h:94: Numeric probes against Bool filters change value before hashing. Bool is accepted through its underlying UInt8 type, but the preserved boolean destination selects truthiness conversion. bloomFilterContains(groupBloomFilterState(CAST(1 AS Bool)), toUInt8(42)) therefore hashes the inserted 1 and returns 1; every nonzero UInt8 probe aliases true, regardless of false_positive_rate. Convert probes using the underlying numeric representation or explicitly validate/reject this case.

⚠️ Majors

  • src/Functions/FunctionsBloomFilter.h:105: Out-of-range Decimal probes violate the documented absent-result contract. Decimal-to-integer conversion takes the ordinary throwing cast path. bloomFilterContains(groupBloomFilterState(toUInt8(42)), toDecimal64('256', 0)) reaches DECIMAL_OVERFLOW before the fractional-part check. Negative whole decimals against unsigned filters also throw, so one invalid probe aborts a vector query. Make range failures produce absent before invoking a throwing conversion, or correct the shared decimal accurate-cast path.
Tests
  • ⚠️ Add stateless coverage for Bool filters with numeric probes outside 0/1, plus valid controls.
  • ⚠️ Extend decimal probe coverage with positive overflow, negative-to-unsigned conversion, and mixed vector probes with valid values and NULL. The new fractional-decimal tests do not cover these range failures.
Final Verdict

Status: ❌ Block. Correct both numeric conversion paths and add the focused regressions above.

@clickhouse-gh clickhouse-gh Bot added the pr-feature Pull request with new product feature label Jun 22, 2026
Comment thread src/Functions/FunctionsBloomFilter.h Resolved
@groeneai

Copy link
Copy Markdown
Collaborator

The separate PR is #125562: it passes --skip 05082_kill_and_system_on_cluster_access_types to the upgrade check's stress phase, so the previous release no longer puts that KILL PART_MOVE_TO_SHARD ... ON CLUSTER entry on its DDL queue.

@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Merged master into the branch (190ec646). The merge was clean, clickhouse builds, and all nine of the PR's stateless tests pass locally.

CI failures on f6dd766d, none caused by groupBloomFilter / bloomFilterContains:

  • 05210_lightweight_update_materialized_cte_in_ignore (Stateless tests (arm_binary, ParallelReplicas, s3 storage, parallel)): master has since made this test robust (5fb7b70cf99, 6f25b41d4b7, b5ac604c8ce), and the merge brings those commits in.
  • Performance Comparison (arm_release, master_head, 1-5/6): the infrastructure could not upload results to CIDB (LogCluster connection failed: ConnectionError), so the job has no verdict.

@groeneai, thanks for the analysis of the Upgrade check failure and for #125562.

@mintlify

mintlify Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Preview approval required

This pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit 5ee1fc5.

Approve preview

Comment thread src/Functions/FunctionsBloomFilter.h Resolved
Preserve both `throwIfCannotProduceFinalizedResult` and `getMergedValueBound` in `IAggregateFunction`.
`accurateCastOrNull` truncates fractional `Decimal` values when converting
them to integers. Reject probes with a nonzero fractional part before
returning the result from `bloomFilterContains`.

Inspect the original decimal value to preserve exact probes for wide
integer filters, whose conversion back to `Decimal` is unsupported.
Add a stateless regression covering all decimal widths, signed and
unsigned probes, wide integers, vector inputs, and `NULL` propagation.

Related: ClickHouse#101841
Set the documented introduction version of `groupBloomFilter` and
`bloomFilterContains` to the current development release, 26.11.

Related: ClickHouse#101841
Keep the structured reference in `FunctionDocumentation` and preserve usage,
storage and sizing guidance outside the generated region. Allow new empty
documentation stubs while retaining protection for existing generated content.
Resolve discovered aggregate pages directly instead of requiring a legacy
migration-map entry.

Related: ClickHouse#101841
Related: ClickHouse#101841 (comment)
Merge ClickHouse/ClickHouse master at 86e0a62.

Related: ClickHouse#101841
@maxknv maxknv added the external Author is not a member of the ClickHouse organization label Nov 2, 2026
alexey-milovidov and others added 4 commits November 5, 2026 06:52
Resolve conflict in `AggregateFunctionFactory::get`: keep master's window-layout fallback for the nested function and the PR's `assertCombinatorIsSupported` check on the final nested function.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts:
#	src/AggregateFunctions/IAggregateFunction.h
Preserve `supportsCombinator` while accepting the removal of
`forEachNestedFunction` and the new `NestedStatesScope`.

Related: ClickHouse#101841
Comment thread src/Functions/FunctionsBloomFilter.h Resolved
Comment thread src/Functions/FunctionsBloomFilter.h Resolved
Treat only exact numeric zero and one as representable in a `Bool` filter. Add scalar, vector, and nullable regression coverage.

Related: ClickHouse#101841 (comment)
Convert integral `Decimal` probes with explicit fractional and range checks before hashing. Cover all decimal widths, signed and unsigned boundaries, wide integers, boolean filters, and nullable vector probes.

Related: ClickHouse#101841 (comment)
Consolidate nine new stateless tests into five focused suites. Move fractional decimal and execution-shape cases into the type/probe suite, nullable array rejection into combinators, and merge cases into storage. Preserve every existing query and expected output.
Preserve Bloom state normalization alongside the new `[[nodiscard]]` annotations in `AggregateFunctionNullBase`.
Avoid an implicit conversion from `int` when constructing the `ColumnUInt8` null map.
Resolve the documentation generator path conflict using the current master layout.

Related: ClickHouse#101841
Preserve aggregate combinator validation while adopting the updated window function handling.

Related: ClickHouse#101841
Include upstream updates fetched during conflict resolution.

Related: ClickHouse#101841
Align release metadata with 26.12 and describe signed zero and NaN representation semantics.

Related: ClickHouse#101841

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

can be tested Allows running workflows for external contributors comp-aggregate-functions Aggregate function implementations (sum, avg, count, quantile, combinators, etc.). external Author is not a member of the ClickHouse organization manual approve Manual approve required to run CI pr-feature Pull request with new product feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants