Skip to content

feat: add diagnostic summaries for HLL and CPC - #232

Merged
tisonkun merged 6 commits into
apache:mainfrom
zhangxinyao88:feat/display-cardinality-sketches
Sep 26, 2026
Merged

tisonkun merged 6 commits into
apache:mainfrom
zhangxinyao88:feat/display-cardinality-sketches

Conversation

@zhangxinyao88

@zhangxinyao88 zhangxinyao88 commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

Part of #212.

Adds summary() to HLL and CPC sketches and unions for diagnostic output that must not be parsed. This replaces the proposed Display implementations and keeps coverage for empty and populated sketches.

Testing

Not run locally: cargo is not available in this environment.

Comment thread datasketches/src/cpc/sketch.rs Outdated
Comment on lines +477 to +483
let flavor = match self.flavor() {
Flavor::Empty => "Empty",
Flavor::Sparse => "Sparse",
Flavor::Hybrid => "Hybrid",
Flavor::Pinned => "Pinned",
Flavor::Sliding => "Sliding",
};

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.

I think you can either just use the Debug impl for flavor here or define a pub const fn as_str for Flavor`.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated this to use the existing Debug implementation for Flavor.

Comment thread datasketches/src/cpc/sketch.rs Outdated
writeln!(
f,
" lower bound : {}",
self.lower_bound(NumStdDev::One)

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.

Why NumStdDev::One? Could you point out the referenced implementation?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point. The Java HLL summary uses one standard deviation, but the Java CPC summary does not include bounds. I removed the CPC lower and upper bounds instead of introducing that choice here.

Comment thread datasketches/src/cpc/sketch.rs Outdated
Comment on lines +497 to +498
" upper bound : {}",
self.upper_bound(NumStdDev::One)

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.

Ditto

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed this together with the lower bound, since the Java CPC summary does not include either bound.

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.

You may use insta for snapshot testing.

However, I have more to consider here now. Let me comment on the issue.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated the exact Display assertions to use insta inline snapshots. I kept the populated cases as focused assertions so we do not snapshot estimator values unnecessarily.

@zhangxinyao88
zhangxinyao88 force-pushed the feat/display-cardinality-sketches branch from 326405e to 1c3e45b Compare September 1, 2026 00:09
@zhangxinyao88

Copy link
Copy Markdown
Contributor Author

@tisonkun, could you take another look when you have time? I addressed the review comments in 1c3e45b.

@tisonkun

Copy link
Copy Markdown
Member

@zhangxinyao88 I left a comment at #212 (comment) that at least we may not implement this function as Display.

@zhangxinyao88 zhangxinyao88 changed the title feat: add Display summaries for HLL and CPC feat: add diagnostic summaries for HLL and CPC Sep 23, 2026
@tisonkun

Copy link
Copy Markdown
Member

Based on Lee's clarification in #212, this is informal, human-readable information about the sketch's current state. I think we can simply improve the existing Debug implementations to make that information easier to read. A separate summary() API adds another interface to learn and maintain without helping this use case.

I've pushed 6b14e51 to take this approach, using debug_struct and the usual {:?} / {:#?} formatting. The output is free to evolve, so I also removed the tests that pin down its presentation.

cargo x check, cargo x test, and cargo x lint pass locally.

@tisonkun
tisonkun enabled auto-merge (squash) September 26, 2026 13:14
@tisonkun
tisonkun merged commit c7e745a into apache:main Sep 26, 2026
10 checks passed
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.

2 participants