feat(clickhouse): execute typed relational aggregates - #649
Merged
Merged
Conversation
zzylol
marked this pull request as ready for review
September 11, 2026 14:21
zzylol
changed the base branch from
fix/clickhouse-exact-dag-provenance
to
main
September 11, 2026 14:26
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.
SQL aggregates above exact relational subtrees were routed through the PromQL summary executor, so original o11y q09/q12 fell back even after their child queries could execute.
This change executes the existing typed
ExactOperation::Aggregateover relational rows. Grouping uses typed values with a sort-and-reduce pass; sum/count/min/max/avg share the same execution path. Integer sums are checked, and integer averages accumulate in i128 before conversion to avoid losing cancellation above 2^53. Empty Map metadata uses ClickHouse'sNothingspelling.Before this PR, an outer SQL SUM over argMax rows could not run in the installed DAG. After this PR, that composition executes locally while its exact leaf stays in ClickHouse. No raw sample store or SQL-specific summary identity is introduced.
Verification: 26 ClickHouse query-engine unit tests pass against the actual pinned sketchlib #139 dependency, including grouped integer sums, overflow, all supported reductions, integer AVG cancellation, and bottom-type metadata. The compiler's four exact-cut tests pass. Native ClickHouse confirms the integer AVG counterexample returns 0.5. Original q07/q09/q12 executed through the external DAG with matching decoded JSON on the final runtime head. q27 executes but has the disclosed one-ULP difference. Independent aggregate source review passed after the AVG correction.
Limitations: nullable numeric aggregate inputs, nonfinite values/results, unsupported intents, and empty min/max remain explicit fallback. Floating reductions can differ by rounding order: q27 differs by one ULP and is not claimed bit-exact. These queries currently have no SDS materialization, so the route is
exact_fallback/external_dag, not ASAP acceleration. No performance claim or screenshot applies. Stacked on #648.