Repository navigation
feat(planner): rewrite avg into sum and count optimizer items - #795
Merged
Merged
Conversation
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>
3 tasks done
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
A2a of #790. Closes #419.
An
avgleaf decomposed to one item with statistics[Sum, Count], which no single sketch can serve (candidate generation rejected it as unservable).aqe_extractor::rewrite_avgnow 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])avgarms inside binary expressions are rewritten tooGrouping, range and modifiers are preserved. Other leaves pass through unchanged.
Interface for later sessions
sum .../count ...), not the originalavgquery. Mapping anavgquery back to its two aggregations inInferenceConfigis tracked as A3b in Tracking: use sketch-bench rqe-optimizer MILP in asap-planner-rs #790 (engine has no Avg yet, Support Avg (and other multi-statistic aggregations) in query engine #463).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