Skip to content

fix(tdigest): fix incorrect min/max default initialization#3463

Open
Tangruilin wants to merge 1 commit intoapache:unstablefrom
Tangruilin:fix#tdigest_reset
Open

fix(tdigest): fix incorrect min/max default initialization#3463
Tangruilin wants to merge 1 commit intoapache:unstablefrom
Tangruilin:fix#tdigest_reset

Conversation

@Tangruilin
Copy link
Copy Markdown
Contributor

CentroidsWithDelta struct was default-initializing min and max to 0, which caused incorrect behavior when merging empty tdigests. Also delete Reset({}) overload to prevent accidental misuse.

Assisted-by: Claude Code:glm-5

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes TDigest empty-merge correctness by ensuring CentroidsWithDelta doesn’t default min/max to 0 (which can corrupt subsequent min/max updates), and prevents accidental Reset({}) calls by explicitly deleting the initializer_list overload.

Changes:

  • Initialize CentroidsWithDelta::{delta,min,max,total_weight} with safe defaults using std::numeric_limits.
  • Delete TDigest::Reset(std::initializer_list<CentroidsWithDelta>) to make Reset({}) a compile-time error.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/types/tdigest.h Sets safe default values for CentroidsWithDelta (notably min/max) to avoid incorrect behavior when empty digests are merged/reset.
src/types/tdigest.cc Deletes Reset(std::initializer_list<...>) to prevent accidental braced-init calls selecting the wrong overload.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/types/tdigest.cc
Comment thread src/types/tdigest.h
Copy link
Copy Markdown
Member

@jihuayu jihuayu left a comment

Choose a reason for hiding this comment

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

General LGTM. Thanks!

Comment thread src/types/tdigest.cc
Comment thread src/types/tdigest.cc
Comment thread src/types/tdigest.h
@Tangruilin Tangruilin requested a review from jihuayu April 26, 2026 09:42
Comment thread tests/cppunit/types/tdigest_test.cc Outdated
CentroidsWithDelta struct was default-initializing min and max to 0,
which caused incorrect behavior when merging empty tdigests. Also
delete Reset({}) overload to prevent accidental misuse.

Assisted-by: Claude Code:glm-5
@sonarqubecloud
Copy link
Copy Markdown

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