Skip to content

promql: add limit_ratio aggregation operator - #443

Draft
petrpan26 wants to merge 3 commits into
opendata-oss:mainfrom
petrpan26:feat/limit_ratio
Draft

promql: add limit_ratio aggregation operator#443
petrpan26 wants to merge 3 commits into
opendata-oss:mainfrom
petrpan26:feat/limit_ratio

Conversation

@petrpan26

Copy link
Copy Markdown

Summary

Adds evaluator support for limit_ratio with Prometheus-compatible grouping and filter-shape output.


  • add limit_ratio aggregation on the absorb-then-finalise breaker path with per-series labelset-hash inclusion
  • widen scalar-param storage to f64 so the same path serves k (cast to i64) and r (used directly)
  • extend lowering and physical planning to recognize limit_ratio
  • add limit_ratio operator tests covering extreme r, NaN, negation-symmetric partition, validity skipping, dynamic r
  • add limit_ratio parity fixtures to aggregators.test

Related 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 warnings
  • cargo fmt --check

Checklist

  • Tests added/updated
  • cargo fmt and cargo clippy pass
  • Documentation updated (if applicable)

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
petrpan26 marked this pull request as draft May 12, 2026 10:11
Hoang Phan 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)
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.

[tsdb] implement the full set of aggregation operators

1 participant