feat(sql): lower temporal and histogram planning bridges - #371
Open
zzylol wants to merge 2 commits into
Open
Conversation
zzylol
force-pushed
the
feat/sql-temporal-histogram
branch
from
September 10, 2026 13:27
3424c71 to
c94370d
Compare
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.
Why
Equivalent ClickHouse planning SQL for PromQL subqueries and classic histograms could not express the temporal evaluation grid or bucket interpolation already present in the canonical query DAG. Those queries therefore stopped at the SQL frontend even though the shared planner and runtime already understand the canonical operations.
What
Adds two planning-only SQL relation markers:
asap_promql_subquery(range_ms, resolution_ms)lowers to the existingQueryExpr::PromqlSubquery.asap_histogram_quantile(q)lowers to the existingAggIntent::HistogramQuantile.How
The SQL frontend registers type-only UDF stubs so DataFusion accepts the marker syntax. Projection lowering consumes each marker and constructs the existing canonical node. The temporal marker must be aliased to an existing child value column, and its surrounding projection is retained. Histogram markers must be the only projected expression. Literal, arity, range, and ambiguity checks fail closed.
Before this PR
SQL could express ordinary and temporal aggregates but could not state PromQL subquery grids or classic cumulative-bucket interpolation in an equivalent planning rewrite.
After this PR
Control planes can supply explicit equivalent planning SQL for these two operations while exact ClickHouse SQL remains the request and fallback identity. No canonical IR, physical DAG, or SDS type changes.
Evidence
The new lowering tests assert the emitted canonical variants and duration/quantile parameters. Invalid marker shapes are rejected.
Verification
cargo test -p asap-frontend-sql— 90 tests passed across unit and integration suites.cargo fmt --all -- --check;git diff --check.Architectural decisions
The bridge reuses existing canonical types instead of adding SQL-specific DAG or SDS variants. The marker is planning-only and is always consumed by lowering, so it cannot reach an executor as an opaque scalar function.
Limitations and follow-up
These markers assert equivalence supplied by the workload author. They are deliberately unavailable as general ClickHouse execution functions. Backend publication must still validate physical/runtime capability and coverage before serving warm results.
Human review — do not complete with an agent