Skip to content

sql.rs: query-requirements derivation duplicated across 3 independent implementations #519

Description

@milindsrivastava1997

SQL's query-requirements derivation (statistic mapping, grouping labels, data range) exists as three separate, non-shared implementations that happen to agree today but have no mechanism keeping them in sync:

  1. asap-query-engine's main path (build_spatiotemporal_context, asap-query-engine/src/engines/simple_engine/sql.rs) derives query_output_labels, statistic_to_compute, and timestamps directly from SQLQueryData/SQLQuery, without going through QueryRequirements at all.
  2. asap-query-engine's capability-matching fallback path calls build_query_requirements_sql, a private SimpleEngine method used only there.
  3. asap-planner-rs's SQLSingleQueryProcessor::get_streaming_aggregation_configs (asap-planner-rs/src/planner/sql.rs) has its own from-scratch get_sql_treatment_type/get_sql_statistics, sharing no code with either function above.

Concretely: parse_single_statistic (query-engine, via AggregationOperator::to_statistics()) and get_sql_statistics (planner-rs, a hand-written match name.to_uppercase()) encode the same name→Vec<Statistic> mapping as two separately-maintained match statements. get_sql_treatment_type (planner-rs: "MIN"|"MAX" => Exact, _ => Approximate) happens to agree with what Statistic::is_approximate() would say for every statistic SQL can produce, but is a separate hand-written check, not a call to that method.

This is the same shape of problem #508 fixed for PromQL, which now has one canonical build_query_requirements_promql shared across all 4 of its own call sites (query-engine's main + fallback paths, planner's SingleQueryProcessor + AQE extractor). For SQL it's three-way, and unlike PromQL there's no cross-crate-shared function to converge onto yet — build_query_requirements_sql is private to asap-query-engine, not exported via asap_types the way PromQL's equivalent is.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions