Skip to content

refactor(legacy_expr): batch 1 — D-purge + Dedup→Distinct rename - #135

Merged
zzylol merged 1 commit into
mainfrom
refactor/legacy-expr-batch-1-dead-purge
May 11, 2026
Merged

zzylol merged 1 commit into
mainfrom
refactor/legacy-expr-batch-1-dead-purge

Conversation

@zzylol

@zzylol zzylol commented May 11, 2026

Copy link
Copy Markdown
Contributor

Summary

Lowest-risk first batch of the legacy_expr retirement plan (the Plan agent's 13-PR sequence). Deletes 10 unused variants + does one structural rename. Lays the groundwork for Batch 2 (A-lifts into canonical L3) and the heavier C-reshape PRs that follow.

What landed

Deleted: 5 QueryExpr variants (0 constructor sites)

Variant Why deleted
JoinSketch { join_key, outer, inner } Sketch-bound physical alternative; design.md says L3 must be intent-only; sketch-bound shape lives at L4 (sketch_algebra::SketchExpr::SketchJoin)
Subquery { alias, expr } Designed for SQL nested SELECT, no parser emits it
WindowFunc { …, frame, … } Designed for SQL OVER(), no parser emits it
SketchCoverage Internal enum; referenced only by its own test
(Dedup→Distinct rename in step 2)

Deleted: 5 ScalarExpr variants (0 constructor sites)

Variant Notes
UnaryOp { op, input }
InSubquery { …, subquery, … }
Case { operand, when_then, else_ }
Cast { expr, to }
VectorBinaryOp { …, vector_match } design.md merges PromQL vector ops into QueryExpr::BinaryOp { vector_match }

Orphaned supporting types also dropped

UnaryOpKind, WindowFuncKind, WindowFrame, FrameUnit, FrameBound, legacy DataType. All had no consumers after the D-purge. The canonical intent_algebra::schema::DataType is untouched.

DedupDistinct rename + N-arity

QueryExpr::Dedup { col: ColumnRef }QueryExpr::Distinct { cols: Vec<ColumnRef> }. Per design.md §6 "What was removed" row 7.

Touched: enum decl, walk/source_name arms, query_parser/mod.rs, physical/stage_split.rs (×2), physical/planner.rs (new display_distinct_cols helper), physical/allocator.rs (incl. routing doc), optimizer/engine.rs (cost factor, deployment-stage map, HLLDedupElim pattern, recursive rewriter, 2 tests), intent_algebra/legacy_lower.rs. HLLDedupElim rule name kept (still semantically accurate).

Canonical AggIntent already clean

intent_algebra/agg_intent.rs has no HistogramQuantile (removed in #133) and no PromQLSubquery. No change needed.

Build + test

  • cargo build --release -p controller — clean
  • cargo build --release -p query_engine_rust — clean
  • cargo test -p controller --lib655 passed, 0 failed (was 656/656; -1 because sketch_coverage_classification test went with the deleted SketchCoverage enum)
  • cargo test -p query_engine_rust --lib -- engines::warm_tier — 13/13 pass

Grep verification (final)

  • JoinSketch | QueryExpr::Subquery | QueryExpr::WindowFunc | SketchCoverage | ScalarExpr::{UnaryOp,InSubquery,Case,Cast,VectorBinaryOp}zero matches.
  • QueryExpr::Dedup | Dedup {zero matches.
  • Remaining ::Subquery\b hits (6) are Expr::Subquery(sq) from external promql_parser / sqlparser AST libraries, not our type.

Diff: 7 files, +66 / -323 (net -257 lines)

controller/src/intent_algebra/legacy_expr.rs   | 177 +-------------------------
controller/src/intent_algebra/legacy_lower.rs  |  20 +--
controller/src/optimizer/engine.rs             |  51 +++-----
controller/src/physical/allocator.rs           |  77 ++---------
controller/src/physical/planner.rs             |  29 ++++-
controller/src/physical/stage_split.rs         |  23 +---
controller/src/query_parser/mod.rs             |  12 +-

Next in the chain

Batch 2 — A-lifts (next PR): Lift Filter, Project, Partition, Distinct, Merge, Join, SetOp, Sort, Limit, BinaryOp into canonical intent_algebra::query_expr::QueryExpr + a minimal typed Predicate (Column/Literal/BinaryOp/IsNull) for Filter.pred. Then Batch 3 sub-PRs cover the C-reshapes (Source→Scan, WindowedAgg un-fusion, SketchAgg→Aggregate@L3, TopK split, AggFunc→AggIntent, PromQL parser-side histogram_quantile→Quantile substitution). Final PR retires legacy_expr.rs + legacy_lower.rs entirely.

🤖 Generated with Claude Code

Lowest-risk first batch of the legacy_expr retirement plan (Plan agent's
13-PR sequence). Deletes 5 QueryExpr variants + 5 ScalarExpr variants
that have ZERO constructor sites (only match arms), and renames
`QueryExpr::Dedup { col }` → `QueryExpr::Distinct { cols: Vec<ColumnRef> }`
with N-arity generalization.

## Deleted variants (zero constructor sites; only match arms)

QueryExpr family:
- `QueryExpr::JoinSketch { join_key, outer, inner }` — sketch-bound
  physical alternative; design.md says L3 must be intent-only and the
  sketch-bound shape belongs at L4 (`sketch_algebra::SketchExpr::SketchJoin`).
  No constructor sites; 5 consumer match arms removed (query_parser,
  physical/{stage_split,planner,allocator}, optimizer/engine).
- `QueryExpr::Subquery { alias, expr }` — designed for SQL nested
  SELECT lowering, but no parser emits it. 6 consumer match arms.
- `QueryExpr::WindowFunc { func, partition_by, order_by, frame, input }`
  — designed for SQL OVER() clauses, no parser emits it. 5 arms.
- `SketchCoverage` (legacy_expr-internal enum) — referenced only by an
  in-file test. Deleted along with the test.

ScalarExpr family:
- `UnaryOp { op, input }` — 0 consumer arms.
- `InSubquery { expr, subquery, negated }` — 0 arms.
- `Case { operand, when_then, else_ }` — 0 arms.
- `Cast { expr, to }` — 0 arms.
- `VectorBinaryOp { op, lhs, rhs, vector_match }` — 0 arms (design.md
  merges PromQL vector ops into `QueryExpr::BinaryOp { vector_match }`).

## Also dropped (orphaned after the D-purge)

- `UnaryOpKind` enum (only used by `UnaryOp`).
- `WindowFuncKind`, `WindowFrame`, `FrameUnit`, `FrameBound` (only used
  by `WindowFunc`).
- Legacy `DataType` enum (only used by `Cast`). The canonical
  `intent_algebra::schema::DataType` is untouched.

Reversible if Batch 2's canonical lift needs them.

## Dedup → Distinct rename + N-arity

`QueryExpr::Dedup { col: ColumnRef }` → `QueryExpr::Distinct { cols: Vec<ColumnRef> }`.

Per design.md §6 "What was removed" row 7: *"Single-column-only spelling
of SQL `DISTINCT`. Replacement: renamed to `Distinct { cols }`,
generalised to N columns"*.

Touched sites:
- legacy_expr.rs enum + walk/source_name match arms
- query_parser/mod.rs (sketch-mapping arm)
- physical/stage_split.rs (walk + PromQL serializer — 2 sites)
- physical/planner.rs (new `display_distinct_cols(&[ColumnRef])` helper)
- physical/allocator.rs (incl. routing doc table)
- optimizer/engine.rs (cost factor, deployment-stage map,
  HLLDedupElim pattern, recursive rewriter, 2 tests)
- intent_algebra/legacy_lower.rs

HLLDedupElim rule struct name kept (semantically still describes the
rule); only test names/asserts updated.

## Canonical AggIntent verification

`controller/src/intent_algebra/agg_intent.rs` already has no
`HistogramQuantile` (removed in #133) and no `PromQLSubquery`. No
change needed.

## Build + test

- `cargo build --release -p controller` — clean
- `cargo build --release -p query_engine_rust` — clean
- `cargo test -p controller --lib` — **655 passed, 0 failed**
  (was 656/656; -1 because `sketch_coverage_classification` test went
  with the deleted `SketchCoverage` enum)
- `cargo test -p query_engine_rust --lib -- engines::warm_tier` — 13/13 pass

## Grep verification

- `JoinSketch | QueryExpr::Subquery | QueryExpr::WindowFunc | SketchCoverage |
   ScalarExpr::{UnaryOp,InSubquery,Case,Cast,VectorBinaryOp}` → zero
  matches across `controller/src/` and `asap-query-engine/src/`.
  (The 6 remaining `::Subquery\b` hits are `Expr::Subquery(sq)` from
  the external `promql_parser` / `sqlparser` AST libraries — not our
  type; pre-existing and out of scope.)
- `QueryExpr::Dedup | Dedup {` → zero matches.

## Diff: 7 files, +66 / -323 (net -257 lines)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@zzylol
zzylol merged commit f555936 into main May 11, 2026
@zzylol
zzylol deleted the refactor/legacy-expr-batch-1-dead-purge 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