Skip to content

feat(promql): range-vector functions over a sub-query argument (#55) - #76

Merged
zzylol merged 1 commit into
mainfrom
feat/range-fn-over-subquery
Jul 2, 2026
Merged

zzylol merged 1 commit into
mainfrom
feat/range-fn-over-subquery

Conversation

@zzylol

@zzylol zzylol commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Closes #55. Generalizes the *_over_time-over-sub-query support (#42) to the whole range-vector family: rate/irate/increase and the counter-derivatives (changes/delta/idelta/deriv/resets/predict_linear/double_exponential_smoothing).

Before / after

rate(sum(m)[5m:]), changes(rate(m[5m])[1h:]), etc. were rejected (expected a range-vector (matrix) argument). Now each lowers to a per-series Aggregate{[f]} directly over the Subquery — the sub-query is the range context, so there is no separate TimeRange.

How

  • Front end (promql.rs): walk_call routes any range function whose matrix arg is a sub-query through a unified range_fn_over_subquery. rate/increase read the window from the sub-query's own range; predict_linear/double_exp thread their scalar params; quantile_over_time reads φ from arg 0.
  • Converter (l2/lower.rs): a PromQLSubquery input is the range context, so (1) no TimeRange is synthesized over it (rate(sub) would otherwise get a spurious TimeRange from its carried window), and (2) the L2 hardening: counter-derivative intent can be emitted range-less if it reaches the converter without a Window #71 counter-derivative range-less guard correctly does not fire when the input is a sub-query.

Verified

rate(sum(m)[5m:])Aggregate{Rate} over Subquery{5m} (no double range); changes(rate(m[5m])[1h:])Aggregate{Changes} over Subquery{1h} over Aggregate{Rate} over TimeRange{5m}; params carried for predict_linear/double_exp. Normal matrix forms unchanged. Flips counter_derivative_over_a_subquery_is_rejected__GAP into passing conformance tests. Full suite green (29 binaries), clippy clean.

🤖 Generated with Claude Code

Generalizes the `*_over_time`-over-sub-query support (#42) to the whole
range-vector family: `rate`/`irate`/`increase` and the counter-derivatives
(`changes`/`delta`/`idelta`/`deriv`/`resets`/`predict_linear`/
`double_exponential_smoothing`). `f(<inst>[range:res])` now lowers to a
per-series `Aggregate{[f]}` directly over the `PromQLSubquery`.

Front end: `walk_call` routes any range function whose matrix argument is a
sub-query through a unified `range_fn_over_subquery` (rate/increase read the
window from the sub-query's own range; predict_linear/double_exp thread
their scalar params; quantile_over_time reads φ from arg 0).

Converter: a `PromQLSubquery` input is the range context, so (1) no
`TimeRange` is synthesized over it — `rate(sub)` would otherwise get a
spurious TimeRange from its carried window — and (2) the #71 counter-
derivative range-less guard correctly does not fire when the input is a
sub-query.

Flips `counter_derivative_over_a_subquery_is_rejected__GAP` into passing
conformance tests (per-series intent directly over the Subquery, no
TimeRange; scalar params carried). Normal matrix forms (`rate(m[5m])`,
`changes(m[15m])`) unchanged. Full workspace suite green; clippy clean.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@zzylol
zzylol merged commit 5a74d36 into main Jul 2, 2026
1 check passed
@zzylol
zzylol deleted the feat/range-fn-over-subquery branch July 2, 2026 22:26
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.

PromQL: rate/increase and counter-derivative functions reject a sub-query argument (generalize #42)

1 participant