Skip to content

MINOR: [C++] Check size() instead of capacity() in TDigest::TDigestImpl::Validate() - #52276

Open
ezbr wants to merge 2 commits into
apache:mainfrom
ezbr:tdigest-validate-size
Open

ezbr wants to merge 2 commits into
apache:mainfrom
ezbr:tdigest-validate-size

Conversation

@ezbr

@ezbr ezbr commented Oct 7, 2026

Copy link
Copy Markdown

Rationale for this change

std::vector::reserve(delta_) only guarantees capacity() >= delta_, not capacity() == delta_. When the C++ standard library and allocator use size-returning allocations (such as C++23 allocate_at_least), reserve(delta_) can immediately set capacity() > delta_, causing TDigestImpl::Validate() to fail with "oversized tdigest buffer" even when the number of centroids is at most delta_.

What changes are included in this PR?

Check tdigests_[0].size() > delta_ || tdigests_[1].size() > delta_ instead of capacity() > delta_ in TDigest::TDigestImpl::Validate().

Are these changes tested?

Yes, covered by existing TDigestTest unit tests in cpp/src/arrow/util/tdigest_test.cc.

Are there any user-facing changes?

No.

Was AI used for this PR?

PR code and description written by:

  • Human
  • AI

Reviewed before submission by:

  • Human
  • AI
  • Not reviewed

…pl::Validate()

`std::vector::reserve(delta_)` only guarantees `capacity() >= delta_`, not `capacity() == delta_`. When the standard library/allocator uses size-returning allocations (such as C++23 `allocate_at_least`), `reserve(delta_)` can immediately set `capacity() > delta_`, causing `TDigestImpl::Validate()` to fail with "oversized tdigest buffer" even when the number of centroids is at most `delta_`.

Check `size() > delta_` instead of `capacity() > delta_` to verify that the tdigest buffer did not expand past `delta_` elements.
Comment thread cpp/src/arrow/util/tdigest.cc Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants