promql: add limit_ratio aggregation operator - #443
Draft
petrpan26 wants to merge 3 commits into
Draft
Conversation
v0.9.0 adds grammar rules for limitk and limit_ratio in the aggregate_op production. v0.8.0 declared these as `%expect-unused` tokens but never bound them in the grammar, so `limitk(...)` queries failed at parse time before this bump. The bump also widens the token id type from u8 to u16. Updated two local helper signatures (aggregate_op_name, binary_op_kind) to match. No behavior change.
petrpan26
marked this pull request as draft
May 12, 2026 10:11
petrpan26
force-pushed
the
feat/limit_ratio
branch
from
May 12, 2026 13:14
ddcb9b7 to
8242d1e
Compare
added 2 commits
May 12, 2026 09:23
This PR adds first-class evaluator support for the limitk aggregation. It hooks AggregateOp::Limitk into the aggregation evaluation path with Prometheus-compatible grouping and filter-shape output. - implement limitk via AggregateKind::Limitk(i64), reusing the topk/bottomk per-group heap as a fixed-capacity push-only buffer (no eviction) - walk inputs in fingerprint-sorted order so selection is stable per query (Blake3 fingerprint already on SeriesSchema; diverges from upstream's xxhash) - extend lower_aggregate's shared K-param block to T_TOPK | T_BOTTOMK | T_LIMITK - extend physical-plan filter-shape to include Limitk - add limitk-focused operator tests covering by/without grouping, k=0/-1/k>n, mixed validity, multi-step independent selection, fingerprint-sort correctness, and out-of-order tile arrival - add limitk parity fixtures in aggregators.test (cardinality assertions; full label assertions where output is fully determined)
This PR adds first-class evaluator support for the limit_ratio aggregation. Inclusion is per-series via labelset hash: r >= 0 includes series whose hash < r; r < 0 includes hash >= 1 + r. r and r-1 partition the input. - implement limit_ratio via AggregateKind::LimitRatio(f64) on the absorb-then-finalise breaker path - compute per-series [0, 1) hash from the upper 64 bits of the u128 labelset fingerprint - widen param_values storage from i64 to f64 so the same scalar-param path serves both k (cast to i64 in k_for_step) and r (read directly in r_for_step) - extend lowering and physical planning to recognize limit_ratio (literal r and scalar(...) param both supported) - add limit_ratio operator tests covering extreme r, NaN r, negation-symmetric partition, per-series consistency across steps, validity skipping, dynamic r, and tile-arrival - add limit_ratio parity fixtures to aggregators.test (cardinality assertions; negation-symmetric sum)
petrpan26
force-pushed
the
feat/limit_ratio
branch
from
May 12, 2026 13:24
8242d1e to
70a4fae
Compare
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.
Summary
Adds evaluator support for
limit_ratiowith Prometheus-compatible grouping and filter-shape output.aggregators.testRelated Issues
Fixes #88
Stacked on
#442 — limitk. This PR's diff will include the limitk commits until #442 lands; rebase after.
Test Plan
cargo test -p opendata-timeseries --lib(825 pass)cargo clippy -p opendata-timeseries --lib --all-targets -- -D warningscargo fmt --checkChecklist
cargo fmtandcargo clippypass