Summary
Add semantic planning parity with ProjectASAP/ASAPQuery#706 for Top-K over sum_over_time and count_over_time.
Reproduction
Both queries lower successfully through frontend-promql, but the normal summary-selection path used by ASAPQuery-backend currently produces no legal summary candidate for at least the value-ranked case:
topk(5, sum_over_time(m[1m]))
topk by (job) (5, count_over_time(m[1m]))
ASAPQuery #706 defines an important semantic distinction:
topk(sum_over_time(...)) ranks each series by the sum of sample values (value-weighted heap);
topk(count_over_time(...)) ranks each series by the number of samples (count-weighted heap).
The current AggIntent::TopK / SketchQuery::TopK representation carries k but does not carry the ranking/weighting basis, so downstream physical compilation cannot preserve this distinction without re-parsing PromQL.
Scope
- Represent the Top-K ranking basis in canonical pre-ASAP and post-ASAP IR using language-neutral semantics.
- Lower the two #706 query shapes to distinct semantic plans.
- Generate legal heap-bearing summary candidates for both nested temporal cases.
- Preserve
by(...) grouping separately from the in-summary item key.
- Reject non-collapsible shapes (
topk(rate(...)), topk(avg_over_time(...)), etc.) rather than silently selecting a wrong summary.
- Keep SQL/other frontends source-compatible by requiring them to choose the appropriate ranking basis explicitly.
Acceptance criteria
- PromQL lowering tests pin the distinct ranking basis for both queries.
- ASAP-aware mapping tests produce heap-bearing candidates with count vs value update semantics.
- End-to-end planner tests cover grouped and ungrouped forms plus negative non-collapsible cases.
- Serialized IR round-trips without dropping the ranking basis.
Downstream execution tracking: ProjectASAP/ASAPQuery-backend#502.
Parent compatibility audit: ProjectASAP/ASAPQuery-backend#501.
Summary
Add semantic planning parity with ProjectASAP/ASAPQuery#706 for Top-K over
sum_over_timeandcount_over_time.Reproduction
Both queries lower successfully through
frontend-promql, but the normal summary-selection path used by ASAPQuery-backend currently produces no legal summary candidate for at least the value-ranked case:ASAPQuery #706 defines an important semantic distinction:
topk(sum_over_time(...))ranks each series by the sum of sample values (value-weighted heap);topk(count_over_time(...))ranks each series by the number of samples (count-weighted heap).The current
AggIntent::TopK/SketchQuery::TopKrepresentation carrieskbut does not carry the ranking/weighting basis, so downstream physical compilation cannot preserve this distinction without re-parsing PromQL.Scope
by(...)grouping separately from the in-summary item key.topk(rate(...)),topk(avg_over_time(...)), etc.) rather than silently selecting a wrong summary.Acceptance criteria
Downstream execution tracking: ProjectASAP/ASAPQuery-backend#502.
Parent compatibility audit: ProjectASAP/ASAPQuery-backend#501.