Skip to content

feat(hll): expose composite cardinality estimates - #294

Merged
tisonkun merged 3 commits into
apache:mainfrom
edouardmulliez:expose-hll-composite-estimate
Oct 8, 2026
Merged

tisonkun merged 3 commits into
apache:mainfrom
edouardmulliez:expose-hll-composite-estimate

Conversation

@edouardmulliez

@edouardmulliez edouardmulliez commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

When an HLL sketch retains valid update history, estimate() uses HIP and can return different estimates for the same values inserted in different orders. Callers currently cannot explicitly select the composite estimator, even though it is already implemented internally.

Add HllSketch::composite_estimate() and HllUnion::composite_estimate(), matching Java's getCompositeEstimate(). The methods query the existing register-based composite estimator in HLL mode and the existing coupon-count estimator in LIST/SET modes. They preserve HIP state, the behavior of estimate(), and the serialization format. The API docs explain the accuracy tradeoff and include usage examples.

@tisonkun
tisonkun requested review from PsiACE and notfilippo and a balanced review from Copilot October 8, 2026 13:54

@notfilippo notfilippo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

4 open findings
What changed in this PR

Expose a public composite cardinality estimator for HLL sketches/unions so callers can request insertion-order-independent estimates (matching Java’s getCompositeEstimate()), without affecting HIP state or serialization.

Changes:

  • Add HllSketch::composite_estimate() and HllUnion::composite_estimate() APIs with docs/examples.
  • Wire composite estimation through HLL array implementations and the shared estimator.
  • Add integration tests covering composite estimate behavior, HIP preservation, and union behavior.
File Description
tests-integration/​tests/​hll_test/​main.rs Registers the new estimate integration test module.
tests-integration/​tests/​hll_test/​estimate.rs Adds tests for composite estimate properties and HIP preservation.
datasketches/​src/​hll/​union.rs Exposes HllUnion::composite_estimate() with documentation.
datasketches/​src/​hll/​sketch.rs Exposes HllSketch::composite_estimate() and clarifies estimate() behavior in docs.
datasketches/​src/​hll/​estimator.rs Makes the underlying composite estimator callable from more places.
datasketches/​src/​hll/​array4.rs Adds register-based composite estimate for HLL4 arrays.
datasketches/​src/​hll/​array6.rs Adds register-based composite estimate for HLL6 arrays.
datasketches/​src/​hll/​array8.rs Adds register-based composite estimate for HLL8 arrays.
CHANGELOG.md Documents the new public APIs.

🧠 Review effort: Lite


Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.

Comment thread datasketches/src/hll/estimator.rs
Comment thread tests-integration/tests/hll_test/estimate.rs
Comment thread tests-integration/tests/hll_test/estimate.rs
Comment thread tests-integration/tests/hll_test/estimate.rs

@tisonkun tisonkun left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally looks good. Thanks for your contribution!

But I wonder if we can improve the document a bit, because I remember that we intentionally reduce some implementation details from user documents. Maybe we don't have to mention HLL mode, set mode and list mode. And the comparison to Java method may be irrelevant for Rust users.

User-facing docs intentionally avoid internal modes and Java method
references; describe only the observable contract instead.
Comment thread datasketches/src/hll/sketch.rs Outdated
Comment thread datasketches/src/hll/union.rs Outdated
Co-authored-by: tison <wander4096@gmail.com>
@tisonkun
tisonkun enabled auto-merge (squash) October 8, 2026 16:56
@tisonkun
tisonkun merged commit 9cf7ddd into apache:main Oct 8, 2026
10 checks passed
@edouardmulliez

Copy link
Copy Markdown
Contributor Author

Thanks a lot @notfilippo and @tisonkun for the review and the follow-up to improve the documentation!

That was really fast!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants