Skip to content

feat(theta): add theta union#145

Merged
tisonkun merged 9 commits into
apache:mainfrom
ZENOTME:codex/union
Jul 18, 2026
Merged

feat(theta): add theta union#145
tisonkun merged 9 commits into
apache:mainfrom
ZENOTME:codex/union

Conversation

@ZENOTME

@ZENOTME ZENOTME commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Summary

  • add stateful ThetaUnion and builder
  • export ThetaUnion from the theta module
  • add union coverage for exact, estimation, compact, seed mismatch, ordering, reset, and edge states

Tests

  • cargo test -p datasketches --features theta

Comment thread datasketches/src/theta/union.rs Outdated

let ordered = ordered || (entries.len() == 1 && theta == MAX_THETA);

if ordered && entries.len() > 1 {

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.

seems no need check with entries.len() > 1, sort_unstable() no-op on single element array.

@ariesdevil ariesdevil 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.

Rest LGTM.

@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 LGTM. Some follow-up suggestions inline, and:

I may prefer to name result/result_with_order to to_sketch as we do for the CpcSketch and HllSketch. Also, we may not need to have two methods but only one with a ordered param.

This is a breaking change since we already use the result_with_order API in ThetaIntersection, but it should be worthy to do the refactor.

ThetaUnionBuilder::default()
}

/// Update this union with a given sketch.

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.

Later we may review all seed_hash != seed_hash checks and add # Errors document.

@tisonkun

Copy link
Copy Markdown
Member

Now that #146 is merged. We may merge this as well.

Is there any logical conflict that should be resolved beforehand?

@ZENOTME

ZENOTME commented Jul 10, 2026

Copy link
Copy Markdown
Contributor Author

Now that #146 is merged. We may merge this as well.

Is there any logical conflict that should be resolved beforehand?

Yes. Let me covert it as a generic version.

@ZENOTME
ZENOTME requested review from ariesdevil and tisonkun July 10, 2026 17:05

@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.

Thanks for your updates!

I'll go through all these changes and perhaps push a few commits to handle visibility issues.

Hopefully in days, but may be delay to next weekend.

use crate::theta_common::hash_table::RawHashTableEntry;

pub(crate) mod private {
pub(crate) trait Sealed {}

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.

BTW: As @tisonkun mentioned on X, pub impl(crate) trait Foo {} just landed in nightly version; maybe we can use this feature?

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.

This crate is a library and we should stay on stable toolchain. And we have an MSRV of 1.86.

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.

Make sense.

tisonkun added 4 commits July 13, 2026 20:51
Signed-off-by: tison <wander4096@gmail.com>
Signed-off-by: tison <wander4096@gmail.com>
Signed-off-by: tison <wander4096@gmail.com>
@tisonkun

Copy link
Copy Markdown
Member

Pushed a few commits to handle part of the structure and visibility issues. I'll handle for:

  • hash_table.rs
  • sketch_view.rs
  • union.rs

... under thetacommon as well and call for a merge.

Signed-off-by: tison <wander4096@gmail.com>
@tisonkun
tisonkun enabled auto-merge (squash) July 18, 2026 09:10
@tisonkun
tisonkun merged commit ee6e1cc into apache:main Jul 18, 2026
10 checks passed
@tisonkun

tisonkun commented Jul 18, 2026

Copy link
Copy Markdown
Member

There is one more pending issue: the two traits we made public in thetacommon are looking a bit strange right now. If you want to make them sealed or handle them differently, we probably need to refactor the tests in union.rs.

It feels very awkward to implement sealed traits for a struct inside the test module itself. We should take a step back and look at the overall scope of these two traits.

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.

3 participants