Skip to content

refactor(legacy_expr): step γ3 — WindowedAgg un-fusion bridge - #142

Merged
zzylol merged 1 commit into
mainfrom
refactor/legacy-expr-step-gamma3-windowedagg
May 12, 2026
Merged

zzylol merged 1 commit into
mainfrom
refactor/legacy-expr-step-gamma3-windowedagg

Conversation

@zzylol

@zzylol zzylol commented May 12, 2026

Copy link
Copy Markdown
Contributor

Summary

Per design.md §3 + §6 "What was removed" row 2: "One canonical form per plan — no WindowedAgg (use Window over Aggregate)".

Follows γ1's strategy (c): keep legacy QueryExpr::WindowedAgg in place; provide a canonical-view helper consumers call on demand. Window-sketch lifecycle invariant preserved — no construction-site rewrites.

New: windowed_agg_bridge.rs (567 lines, 12 tests)

pub fn bridge_windowed_agg_to_canonical(
    agg: &AggIntent, window: &WindowSpec,
    col: &LegacyColumnRef, parent_schema: &Schema,
) -> Result<BridgedWindowedAgg, BridgeError>;

pub fn output_schema_for_windowed_agg(
    input: &Schema, by: &[ColumnId], aggs: &[AggIntent],
) -> Schema;

BridgedWindowedAgg { window_kind, window_size, window_slide, inner: BridgedAggregate } — stacks γ1's BridgedAggregate as the inner Aggregate layer.

Legacy Tumbling/Sliding/Session → canonical WindowKind. Unbounded/Landmark defer via BridgeError::UnsupportedWindowKind.

File placement: separate module

Rationale: WindowedAgg fuses TWO canonical layers (Window over Aggregate). Mixing single-layer + stacked-layer bridges in one file dilutes each surface. γ1's BridgedAggregate is pub-imported as a field — no duplication.

Demo wire

physical/allocator.rs::alloc_node WindowedAgg arm calls the bridge after recursing into input. Appends "canonical view: Window(kind=…, size=…, slide=…) over Aggregate(by_len=…, intent=…)" to NodeAnnotation.rationale. Legacy emit + lifecycle unchanged.

Build + test

  • cargo build --release -p controller clean
  • cargo test -p controller --lib700 passed (was 688 post-γ1; +12 new tests)
  • cargo test -p controller --bin controller — 27 passed

Diff: 3 files, +627 / -2

🤖 Generated with Claude Code

Per design.md §3 line ~48 + §6 "What was removed" row 2: "One canonical
form per plan — no `WindowedAgg` (use `Window` over `Aggregate`)".

Follows γ1's strategy (c): keep legacy `QueryExpr::WindowedAgg`
variant in place; provide a canonical-view helper consumers call on
demand. No construction-site rewrites; window-sketch lifecycle
invariant preserved.

```rust
pub fn bridge_windowed_agg_to_canonical(
    agg: &AggIntent,
    window: &WindowSpec,
    col: &LegacyColumnRef,
    parent_schema: &Schema,
) -> Result<BridgedWindowedAgg, BridgeError>;

pub fn output_schema_for_windowed_agg(
    input: &Schema, by: &[ColumnId], aggs: &[AggIntent],
) -> Schema;
```

`BridgedWindowedAgg { window_kind, window_size, window_slide, inner: BridgedAggregate }`
— stacks γ1's `BridgedAggregate` as the inner Aggregate layer.
Inner `by = vec![col_id]`, `aggs = vec![agg.clone()]`, `having = None`.

Legacy `Tumbling/Sliding/Session` map to canonical `WindowKind`.
`Unbounded`/`Landmark` defer via `BridgeError::UnsupportedWindowKind`.

Rationale (documented in module doc-comment): WindowedAgg fuses TWO
canonical layers (Window over Aggregate). Mixing single-layer and
stacked-layer bridges in one file would dilute each surface. γ1's
`BridgedAggregate` is `pub`-imported and reused as a field — no
duplication.

- happy path (tumbling/sliding/session)
- unbounded/landmark → defer
- Named col resolution; SampleValue
- unknown col / Wildcard → ResolveError
- output_schema strip time, carry by + agg cols, drop out-of-range ids
- end-to-end round-trip through output_schema_helper

`physical/allocator.rs::alloc_node`'s `WindowedAgg` arm calls the
bridge after recursing into `input`. On success, appends
"canonical view: Window(kind=…, size=…, slide=…) over
Aggregate(by_len=…, intent=…)" to `node.annotation.rationale`.

Legacy emit shape unchanged — `alloc_sketch_agg` still receives
`agg`/`col` and emits `QueryExpr::SketchAgg`. The window-sketch
lifecycle invariant is preserved.

- `cargo build --release -p controller` — clean
- `cargo test -p controller --lib` — **700 passed** (was 688 post-γ1;
  +12 new windowed_agg_bridge tests)
- `cargo test -p controller --bin controller` — 27 passed

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@zzylol
zzylol force-pushed the refactor/legacy-expr-step-gamma3-windowedagg branch from 67a120a to d7b9125 Compare May 12, 2026 01:23
@zzylol
zzylol merged commit 4d80f86 into main May 12, 2026
@zzylol
zzylol deleted the refactor/legacy-expr-step-gamma3-windowedagg 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