Skip to content

Elastic Avg: engine queries Rate but planner precomputes Sum+Count #456

Closed

Description

@milindsrivastava1997

Bug: Mismatch between planner and engine for Elastic Avg aggregation.

Planner (planner/elastic_dsl.rs:157-162) precomputes [Sum, Count] sketches.
Engine (simple_engine/elastic.rs:122) queries Statistic::Rate at runtime.

Engine will miss precomputed data or hit the wrong accumulator for any Elastic Avg query.

Fix: Engine should query Sum and Count and divide, matching the planner.

Activity

  1. milindsrivastava1997 commented on Jun 28, 2026

    @milindsrivastava1997
    ContributorAuthor

    Fixed in this branch by returning None from build_query_metadata_elastic for Avg queries (elastic.rs), which causes graceful fallback to Prometheus — the same behavior SQL and PromQL already have for Avg (SQL's parse_single_statistic returns None when the statistic maps to multiple values; PromQL's context builder returns None when statistics_to_compute.len() != 1).

    The previous code used Statistic::Rate for Avg, which was completely wrong — the planner precomputes [Sum, Count] (two separate MultipleSum accumulators), not a rate accumulator. This would have returned incorrect results rather than falling back.

    Properly serving Avg requires querying both the Sum and Count accumulators then dividing — that's a deeper engine change tracked in a follow-up issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions