You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Avg requires two precomputed accumulators — one for Sum and one for Count — and a divide at read time. The planner already handles this correctly: both the SQL and Elastic DSL planners map `Avg` → `[Statistic::Sum, Statistic::Count]`, producing two separate `MultipleSum` aggregation configs.
The query engine does not support this yet. All three paths return `None` (Prometheus fallback) for Avg:
PromQL: `get_statistics_to_compute()` returns `[Sum, Count]` for `avg`/`avg_over_time`; the `len != 1` guard in `build_promql_execution_context_tail` returns `None`
SQL: `parse_single_statistic("avg")` returns `None` because `AggregationOperator::Avg.to_statistics()` yields two statistics
Root cause
`QueryMetadata.statistic_to_compute` is a single `Statistic`. Avg needs two lookups (Sum agg ID + Count agg ID) and a divide. `get_aggregation_id_info` also rejects query configs with two value-type aggregations ("Query config has two value-type aggregations (expected at most one)"), so even if we had the right statistic, the agg resolution would fail.
What a fix needs
A way for the engine to look up two value-type aggregation IDs from a query config (Sum and Count), distinguished by `aggregation_sub_type` ("sum" vs "count")
Execute both store queries, then divide element-wise (sum / count) to produce the final result
Handle count == 0 (emit NaN or skip)
This applies to all three query paths (Elastic, PromQL, SQL).
Background
Avg requires two precomputed accumulators — one for Sum and one for Count — and a divide at read time. The planner already handles this correctly: both the SQL and Elastic DSL planners map `Avg` → `[Statistic::Sum, Statistic::Count]`, producing two separate `MultipleSum` aggregation configs.
The query engine does not support this yet. All three paths return `None` (Prometheus fallback) for Avg:
Root cause
`QueryMetadata.statistic_to_compute` is a single `Statistic`. Avg needs two lookups (Sum agg ID + Count agg ID) and a divide. `get_aggregation_id_info` also rejects query configs with two value-type aggregations ("Query config has two value-type aggregations (expected at most one)"), so even if we had the right statistic, the agg resolution would fail.
What a fix needs
This applies to all three query paths (Elastic, PromQL, SQL).