Skip to content

feat(clickhouse): execute typed relational aggregates - #649

Merged
zzylol merged 16 commits into
mainfrom
feat/clickhouse-relational-aggregate
Sep 11, 2026
Merged

zzylol merged 16 commits into
mainfrom
feat/clickhouse-relational-aggregate

Conversation

@zzylol

@zzylol zzylol commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

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::Aggregate over 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's Nothing spelling.

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.

@zzylol
zzylol marked this pull request as ready for review September 11, 2026 14:21
@zzylol
zzylol changed the base branch from fix/clickhouse-exact-dag-provenance to main September 11, 2026 14:26
@zzylol
zzylol merged commit d75782f into main Sep 11, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant