Skip to content

feat: add lagInFrame/leadInFrame to WindowFuncKind, add Clickhouse window function catalog - #269

Merged
milindsrivastava1997 merged 1 commit into
mainfrom
267-laginframe-leadinframe-windowfunckind
Aug 24, 2026
Merged

milindsrivastava1997 merged 1 commit into
mainfrom
267-laginframe-leadinframe-windowfunckind

Conversation

@milindsrivastava1997

@milindsrivastava1997 milindsrivastava1997 commented Aug 24, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Added LagInFrame/LeadInFrame variants to WindowFuncKind that are specific to Clickhouse. These are distinct from Lag/Lead which are ANSI (Clickhouse's behavior is different from ANSI)
  • Added catalog-driven mechanism for window functions: CLICKHOUSE_WINDOW_BUILTINS table in sql-function-catalog.
  • WindowFuncKind still has no frame representation (SQL: ClickHouse's lagInFrame window function needs window-frame modeling #231), so these lower and behave like plain Lag/Lead today — the tag is correct, the frame-respecting behavior isn't modeled yet.
  • Updates the two pinned SQL-corpus tests (bgp_analytics, bgp_jan2024_workload) to reflect the new coverage: bgp_analytics query 11 now lowers end to end; in bgp_jan2024_workload, 3 of the 6 lagInFrame occurrences now clear (the other 3 still fail on unrelated unregistered builtins — dateDiff, toString — out of scope here).

Closes #267.

Test plan

  • cargo test --workspace — all green
  • cargo clippy --workspace --all-targets — clean on affected crates
  • New unit tests: lag_in_frame_lowers_to_its_own_kind_not_lag, lead_in_frame_lowers_to_its_own_kind_not_lead (sql_lowering.rs)
  • New catalog tests for CLICKHOUSE_WINDOW_BUILTINS lookup/lowercase/non-shadowing invariants

🤖 Generated with Claude Code

…nts (#267)

Mapping ClickHouse's frame-respecting lagInFrame/leadInFrame onto the
existing Lag/Lead variants would silently ignore the window frame clause,
since ANSI LAG/LEAD (and DataFusion's native lag/lead) are defined to ignore
it entirely. Add distinct WindowFuncKind::LagInFrame/LeadInFrame variants
instead, so the frame clause is never conflated away.

DataFusion's planner rejects lagInFrame/leadInFrame outright as unknown
functions -- unlike lag/lead, they need a stub WindowUDF registered (mirroring
the existing CLICKHOUSE_BUILTINS/CLICKHOUSE_SCALAR_BUILTINS mechanism), so
this adds a CLICKHOUSE_WINDOW_BUILTINS catalog table alongside them.

WindowFuncKind still has no frame representation, so these lower and behave
like plain Lag/Lead today -- the tag is correct, the frame-respecting
behavior isn't modeled yet (#231).

Updates the two pinned SQL-corpus tests (bgp_analytics, bgp_jan2024_workload)
to reflect the new coverage.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@milindsrivastava1997 milindsrivastava1997 changed the title SQL: give lagInFrame/leadInFrame their own WindowFuncKind variants feat: add lagInFrame/leadInFrame to WindowFuncKind, add Clickhouse window function catalog Aug 24, 2026
@milindsrivastava1997
milindsrivastava1997 marked this pull request as ready for review August 24, 2026 01:01
@milindsrivastava1997
milindsrivastava1997 merged commit 7e5afa8 into main Aug 24, 2026
5 of 8 checks passed
@milindsrivastava1997
milindsrivastava1997 deleted the 267-laginframe-leadinframe-windowfunckind branch August 24, 2026 01:32
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.

SQL: lagInFrame/leadInFrame need distinct WindowFuncKind variants, not Lag/Lead

2 participants