Skip to content

refactor(intent_algebra): retire SketchAgg/WindowedAgg — legacy_expr is a pure L2 IR - #229

Merged
zzylol merged 1 commit into
mainfrom
pr-slim-legacy-expr
May 14, 2026
Merged

zzylol merged 1 commit into
mainfrom
pr-slim-legacy-expr

Conversation

@zzylol

@zzylol zzylol commented May 14, 2026

Copy link
Copy Markdown
Contributor

Follow-up to #228.

Summary

#228 folded the legacy_lower sketch-fusion pass into convert_root, but the sketch-fused legacy Layer-3 IR (SketchAgg / WindowedAgg) still existed as the intermediate between two internal walks. This collapses that to a single walk and deletes the intermediate IR.

  • convert's Aggregate arm now does the single-statistic sketchable fusion directly in canonical termsWindow-input → Window { Aggregate { by: [] } }, GROUP BY keys → wrapping Partition, StdDev/VarianceMerge of sibling quantile aggregates — instead of emitting intermediate legacy nodes. convert_root is now just Binder::bind + convert.
  • legacy_expr::QueryExpr: SketchAgg and WindowedAgg variants removed; WindowSpec / WindowKind removed (only WindowedAgg used them). legacy_expr is now a pure Layer-2 relational IR.
  • legacy_to_canonical: the SketchAgg/WindowedAgg convert arms, lower_to_sketch_algebra, lower_aggregate, map_window_kind, and the lower_tests module are deleted.
  • binder.rs: collect_referenced_columns drops the SketchAgg/WindowedAgg arm — the converter only ever resolves group-by keys positionally, never AggItem.col.

Behavior unchanged for every tree the parsers emit: the merged Aggregate arm matches the raw Window input, which is exact because the parsers never nest Aggregate directly over Window directly over another sketchable Aggregate — the only shape where raw vs. sketch-lowered input would diverge.

window_fusion.rs tests (which built legacy WindowedAgg by hand) are rewritten to build the canonical Window { Aggregate } shape directly or via L2 Aggregate { Window } + convert_root. design.md §3/§6 stale legacy_lower / fused-L3 references refreshed.

Net: ~520 lines deleted.

Test plan

  • cargo build --workspace clean
  • cargo test -p control_plane — 754 tests pass (727 + 27), 0 failures
  • window_fusion equivalence harness green end-to-end against the canonical planner

🤖 Generated with Claude Code

…is now a pure L2 IR

PR #228 folded the `legacy_lower` sketch-fusion pass into `convert_root`,
but the sketch-fused legacy Layer-3 IR (`SketchAgg` / `WindowedAgg`) still
existed as the intermediate between two internal walks. This collapses
that to a single walk and deletes the intermediate.

`convert`'s `Aggregate` arm now does the single-statistic sketchable
fusion directly in canonical terms — `Window`-input → `Window { Aggregate
{ by: [] } }`, `GROUP BY` keys → wrapping `Partition`, `StdDev` /
`Variance` → `Merge` of sibling quantile aggregates — instead of emitting
intermediate `SketchAgg` / `WindowedAgg` nodes for the (now-deleted)
second walk to un-fold. `convert_root` is just `Binder::bind` + `convert`.

With the fusion done in canonical terms, the legacy IR has no remaining
producer or consumer of the fused variants, so they're removed:

  * `legacy_expr::QueryExpr`: `SketchAgg` and `WindowedAgg` variants gone;
    `WindowSpec` / `WindowKind` (only `WindowedAgg` used them) gone.
    `legacy_expr` is now a pure Layer-2 *relational* IR.
  * `legacy_to_canonical`: the `SketchAgg` / `WindowedAgg` convert arms,
    `lower_to_sketch_algebra`, `lower_aggregate`, `map_window_kind`, and
    the `lower_tests` module are deleted.
  * `binder.rs`: `collect_referenced_columns` drops the
    `SketchAgg`/`WindowedAgg` arm — the converter never resolved
    `AggItem.col` positionally anyway, only group-by keys.

Behavior is unchanged for every tree the parsers emit: the merged
`Aggregate` arm matches the *raw* `Window` input, which is exact because
the parsers never nest `Aggregate` directly over `Window` directly over
another sketchable `Aggregate` — the only shape where raw vs.
sketch-lowered input would diverge.

`window_fusion.rs` tests, which built legacy `WindowedAgg` nodes by hand,
are rewritten to build the canonical `Window { Aggregate }` shape directly
(or L2 `Aggregate { Window }` + `convert_root`). design.md §3/§6 stale
`legacy_lower` / fused-L3 references refreshed.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@zzylol
zzylol merged commit 17cc7e4 into main May 14, 2026
@zzylol
zzylol deleted the pr-slim-legacy-expr branch July 17, 2026 20:06
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