Skip to content

feat(planner): rewrite avg into sum and count optimizer items - #795

Merged
milindsrivastava1997 merged 1 commit into
mainfrom
790-a2a-avg-rewrite
Oct 5, 2026
Merged

milindsrivastava1997 merged 1 commit into
mainfrom
790-a2a-avg-rewrite

Conversation

@milindsrivastava1997

Copy link
Copy Markdown
Contributor

Summary

A2a of #790. Closes #419.

An avg leaf decomposed to one item with statistics [Sum, Count], which no single sketch can serve (candidate generation rejected it as unservable). aqe_extractor::rewrite_avg now rewrites the PromQL AST of each leaf before requirements are extracted:

  • avg by (l) (x) → sum by (l) (x), count by (l) (x)
  • avg_over_time(x[5m]) → sum_over_time(x[5m]), count_over_time(x[5m])
  • avg arms inside binary expressions are rewritten too

Grouping, range and modifiers are preserved. Other leaves pass through unchanged.

Interface for later sessions

Verification

  • cargo test -p asap_planner (3 new tests; all fail with the rewrite disabled)
  • cargo clippy -p asap_planner --all-targets --all-features -- -D warnings, cargo fmt --all -- --check

🤖 Generated with Claude Code

An avg leaf decomposes to a [Sum, Count] item that no single sketch can
serve. Rewrite avg / avg_over_time leaves into their sum and count leaves
before extracting optimizer items.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@milindsrivastava1997
milindsrivastava1997 merged commit 8b2b9ed into main Oct 5, 2026
8 checks passed
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.

planner/optimizer: decide support for multi-statistic AQEs (e.g. avg)

1 participant