Repository navigation
fix: distinguish empty sketch queries from invalid arguments - #295
Merged
Merged
Conversation
Return None for valid queries on an empty sketch or sorted view, and validate ranks and split points before checking emptiness. Document the query contract and cover invalid inputs, empty arguments, and endpoints. Co-authored-by: Jiawei Zhao <Phoenix500526@163.com>
Apply the query contract to REQ sketches and sorted views, preserving exact extrema and validating ranks and split points before emptiness. Document the migration and distinguish sample queries from error models. Co-authored-by: Jiawei Zhao <Phoenix500526@163.com>
Return Result<Option<_>, Error> from rank, quantile, quantiles, CDF, and PMF queries on both mutable and frozen digests. Validate arguments before emptiness and compression, preserving None for empty data. Migrate callers, test invalid arguments and valid boundary queries, and document the empty-result inventory across all sketch families. Co-authored-by: Jiawei Zhao <Phoenix500526@163.com>
tisonkun
force-pushed
the
codex/kll-req-query-semantics
branch
from
October 20, 2026 07:57
e93ec9c to
6947ee0
Compare
Remove the crate-wide query inventory and repeated module summaries. Keep empty-result and argument-error contracts on the query methods, and record the shared design principles briefly in CONTRIBUTING.
Make all hidden doctest imports visible and record the example convention. Keep trailing hidden Ok expressions that allow examples to use ?.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
KLL and REQ reported empty distributions as
InvalidArgument, while T-Digest returnedNonebut panicked on invalid query arguments. This change separates absent results from invalid requests, following the discussion in #266 and the implementation in #273.Design
InvalidArgumenteven when the sketch is empty.None. Queries that also validate arguments returnResult<Option<T>, Error>.These principles are recorded briefly in CONTRIBUTING.md. Each method documents its own empty-result and error contract.
API changes
rankOption<f64>quantile,quantiles,cdf,pmfResult<Option<_>, Error>TDigest/TDigestMutrank,quantile,quantiles,cdf,pmfResult<Option<_>, Error>The changes include the queries exposed by KLL/REQ sorted views. Valid queries on empty data return
NoneorOk(None); callers of fallible queries can use?before handling the optional result.[0, 1], NaN arguments, and invalid split-point ordering produce errors where applicable.quantiles(&[])returnsOk(Some(vec![]));cdf(&[])andpmf(&[])returnOk(Some(vec![1.0])). Empty data returnsOk(None).Optioncontracts such as extrema and intersection initialization. Those APIs retain their behavior.Commits
5bda675 fix(kll): distinguish empty queries from invalid argumentsfd871f9 fix(req): distinguish empty queries from invalid arguments6947ee0 fix(tdigest): distinguish empty queries from invalid argumentsd938a1b docs: keep query contracts on their methods4e0ecc6 docs: show imports in doctest examplesThe first three commits each cover one sketch family. Documentation cleanup and visible doctest imports are separate commits. Hidden trailing
Ok(...)expressions remain available for examples using?.Validation
cargo x checkcargo x test, including 144 doctests and cross-language serialization testscargo x lintCoverage includes empty, singleton, and compressed states; invalid arguments before emptiness; empty query slices; valid infinite T-Digest rank/split-point arguments; and existing endpoint and large-weight regressions.
Credit
Adapted from @Phoenix500526's work in #273. The three implementation commits retain: