[feature](function) add uniq_theta theta-sketch distinct-count aggregate - #66241
Open
lzydmxy wants to merge 1 commit into
Open
[feature](function) add uniq_theta theta-sketch distinct-count aggregate#66241lzydmxy wants to merge 1 commit into
lzydmxy wants to merge 1 commit into
Conversation
Add uniq_theta, a theta-sketch based approximate distinct-count aggregate returning BIGINT, ported from ClickHouse uniqTheta and backed by the Apache DataSketches library (contrib/datasketches-cpp submodule added in apache#63143). The aggregate reuses the generic agg_state combinator framework so uniq_theta_state / uniq_theta_merge / uniq_theta_union are auto-derived with no extra wiring. Includes BE gtest, FE unit test, and regression suites. Signed-off-by: lizhuoyu5 <lizhuoyu5@jd.com>
lzydmxy
requested review from
924060929,
englefly,
morrySnow and
starocean999
as code owners
July 29, 2026 13:19
Contributor
|
Thank you for your contribution to Apache Doris. Please clearly describe your PR:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add uniq_theta, a theta-sketch based approximate distinct-count aggregate returning BIGINT, ported from ClickHouse uniqTheta and backed by the Apache DataSketches library (contrib/datasketches-cpp submodule added in #63143). The aggregate reuses the generic agg_state combinator framework so uniq_theta_state / uniq_theta_merge / uniq_theta_union are auto-derived with no extra wiring. Includes BE gtest, FE unit test, and regression suites.
What problem does this PR solve?
Issue Number: close #66240
Related PR: #63143
Problem Summary:
Doris only has HyperLogLog-based
approx_count_distinct/ndv, which supportsunionbut not clean intersection or difference on the serialized state.This PR adds
uniq_theta, an approximate distinct-count aggregate backed bythe Apache DataSketches Theta Sketch (ported from ClickHouse
uniqTheta). Thetasketches add capabilities HLL lacks: set operations (union / intersect /
difference) on the serialized sketch, precompute-once/query-many via mergeable
agg_state, and cross-engine-compatible sketch bytes. Relative error is ~3.125%(95% confidence, default 4096 nominal entries), exact for small cardinalities.
The
contrib/datasketches-cppsubmodule and its build wiring were already addedby #63143, so this PR only adds the aggregate itself.
Release note
Add aggregate function uniq_theta, a Theta-sketch (Apache DataSketches) based
approximate distinct-count function, together with its uniq_theta_state /
uniq_theta_merge / uniq_theta_union agg_state combinators.
Check List (For Author)
Test
Behavior changed:
Does this need documentation?
Check List (For Reviewer who merge this PR)