Skip to content

feat(core): converge grouped *_over_time onto positional Aggregate.by (closes #8) - #9

Merged
zzylol merged 2 commits into
mainfrom
feat/promql-over-time-grouping
May 27, 2026
Merged

zzylol merged 2 commits into
mainfrom
feat/promql-over-time-grouping

Conversation

@zzylol

@zzylol zzylol commented May 27, 2026

Copy link
Copy Markdown
Contributor

What

Closes #8 — the residual of PR #5's review D. Grouped *_over_time aggregates now converge onto a positional Aggregate.by, the same shape SQL GROUP BY and the rate/increase cases already produce — eliminating the last name-based Partition-as-grouping for cross-series aggregates.

sum by(instance) (avg_over_time(node_cpu_seconds_total[5m]))
  before: Partition{By([instance])} ∘ Aggregate{by:[],[Sum]} ∘ Window{Aggregate{[Avg]}}
  after:  Aggregate{by:[instance], [Sum]} ∘ Window{Aggregate{[Avg]}}   (no Partition)

Why it was deferred, and why it's now clean

The *_over_time reduction lowers to Window { Aggregate{ by:[], [reducer] } }, and that inner Aggregate collapsed its schema to [reducer], dropping the label x — so the outer cross-series aggregate had no x to resolve into Aggregate.by. The two blockers from review D both dissolve:

  • Shared AggIntent variants (avg_over_time vs cross-series avg, both AggIntent::Avg): resolved structurally — the enclosing time Window is the per-series discriminator, no intent disambiguation needed.
  • Sample-value resolution (the topk by(h)(avg_over_time(…)) regression caught in D): the preserved value column is kept named value, so SampleValue resolves it by name regardless of how many label columns are present.

How

One behavioral change in output_schema_in (query_expr.rs): a time Window over a single-agg, by:[] Aggregate is a per-series reduction → re-derive its schema label-preservingly (keep every label, replace only the sample value). The per-series logic is factored into per_series_reduction_schema, shared with the rate/increase (D) path. The converter is unchanged — with labels preserved, its existing key resolution lands by=[x].

Scope

Converges sum/count/avg/quantile-by(x) over *_over_time. topk/bottomk by(x) go through the generic Sort+Limit path, where grouping rides a Partition by a different mechanism — left as-is (and verified non-regressing).

Tests

  • Updated the two flipped shape tests (quantile_over_time, count_over_time grouped → Aggregate.by).
  • Added: a Window-over-Aggregate label-preservation unit test; a sum by(instance)(avg_over_time(...)) conformance test.
  • topk_over_avg_is_generic_sort_limit still green (no regression).
  • Full workspace green (135 tests), clippy --all-targets -D warnings + fmt --check clean.

🤖 Generated with Claude Code

zzylol and others added 2 commits May 27, 2026 12:24
…closes #8)

The residual of review D: `sum by(x)(avg_over_time(m[w]))` (and quantile/count/
…_over_time) still parked its group key in a name-based `Partition`, because the
inner `*_over_time` reduction — `Window { Aggregate{ by:[], [reducer] } }` —
collapsed its output schema to `[reducer]`, dropping `x`, so the outer
cross-series aggregate had nothing to resolve into `Aggregate.by`.

Fix: recognize that a per-series time-window reduction is *label-preserving* —
the same property `rate`/`increase` already have (D), just under a time `Window`
rather than carried in the intent. In `output_schema_in`, the `Window`-over-
`Aggregate` arm now re-derives the schema label-preservingly (keep every label,
replace only the sample value, kept named `value`). The discriminator is purely
structural — the enclosing `Window` — which sidesteps the shared-`AggIntent`
problem (`avg_over_time` and cross-series `avg` are both `AggIntent::Avg`).

With labels preserved, the converter's existing key-resolution lands `by=[x]`
unchanged — no converter edit. So `sum/count/avg/quantile by(x)(*_over_time(…))`
now emit the same positional shape as SQL. Naming the preserved value column
`value` keeps `SampleValue` resolvable, so `topk by(h)(avg_over_time(…))` (the
generic Sort+Limit path, grouping still via Partition) does not regress.

Factored the per-series logic into `per_series_reduction_schema`, shared by the
rate/increase (Aggregate) and *_over_time (Window) arms. Updated the two flipped
shape tests; added a Window-over-Aggregate label-preservation unit test and a
`sum by(instance)(avg_over_time(...))` conformance test. Full suite green (135),
clippy -D warnings + fmt clean.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…time convergence

The converter fused-path comment and the promql.rs mapping table still described
PromQL grouping as landing in a name-based `Partition`; after the D + #8 work it
resolves positionally into `Aggregate.by` (Partition is only a fallback for
windowed/unresolved keys). Doc-only — no behavior change.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@zzylol
zzylol merged commit 16e9204 into main May 27, 2026
1 check passed
@zzylol
zzylol deleted the feat/promql-over-time-grouping branch May 27, 2026 18:43
zzylol added a commit that referenced this pull request Aug 24, 2026
Restructure the flat 19-section developer guide into the three-part
structure the doc owner asked for: Part 1 - Code Architecture, Part 2
- Interfaces and Definitions, Part 3 - How to Add X, Y, Z (each ending
in how to verify). Content is moved, not rewritten:

Part 1 (Mental model first, per doc-owner follow-up, then a new
whole-PR architecture diagram, then "How the current pieces fit
together"):
- old #1 Mental model -> Part 1 #1
- new: whole-PR architecture diagram (TargetSubDAG's two entry points
  through ReplacementStrategy, PlanSpace/cost_sorted, explanation.rs,
  to a downstream consumer) -> Part 1 #2
- old #3 How the current pieces fit together -> Part 1 #3

Part 2:
- old Terminology's "Implementation" definition merged into the
  Glossary as one more entry (### Implementation), next to
  ReplacementStrategy
- old #2 Glossary -> Part 2 #1 (plus the merged Implementation entry
  and old #10 Matcher, retitled to match glossary-entry style)
- old #10 Matcher (implementation.rs) -> ### Matcher inside the
  Glossary; implementation.rs no longer exists, so the stale title
  is fixed
- old #19's definitional content (ReplacementExplanation/
  ExplanationKind shapes, node_hash, why there's no ExplanationRule
  trait, location-text ownership) -> Part 2 #2

Part 3:
- old #4, #5, #6, #7, #13, #14 -> Part 3 #1, Adding a new
  ReplacementStrategy (ending in Testing a new strategy)
- old #8, #9, #15 -> Part 3 #2, Adding or customizing a CostModel
  (ending in Testing a new cost model)
- old #12 -> Part 3 #3, Adding a new sketch algorithm, with its
  stale implementation.rs/binder references fixed to replacement.rs/
  construct_summary vocabulary, plus a new "Verifying a new sketch
  algorithm" close grounded in the existing coverage-matrix tests
- old #11, #16, #17, #18 -> Part 3 #4-#7 (capstone + closing
  reference material); #18's extension-map table's implementation.rs
  row fixed to replacement.rs
- old #19's "Using it"/"Adding a new kind" content -> Part 3 #8,
  Using and extending explanation.rs

cargo build --workspace --all-targets is clean (docs-only change).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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.

Converge grouped *_over_time onto positional Aggregate.by (residual of review D)

1 participant