Skip to content

fix(lint)!: resolve windows after parentheses and take a depth limit in parse_sql - #260

Merged
kvlonge merged 2 commits into
mainfrom
fix/lint-subquery-windows
Nov 18, 2026
Merged

kvlonge merged 2 commits into
mainfrom
fix/lint-subquery-windows

Conversation

@kvlonge

@kvlonge kvlonge commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

Why

Two lint gaps reach SQLClean.

  • Since a WINDOW written after a parenthesized query stays on the Databricks subquery node, the ranking rules no longer found it. SQLCLEAN018 and SQLCLEAN043 were silent for (SELECT order_id, ROW_NUMBER() OVER w AS rn FROM orders) WINDOW w AS (ORDER BY ...), with or without a WITH before the parentheses.
  • parse_sql always parsed within the default limit of 256 nested calls. SQL that a lint request with a raised max_function_call_depth accepted was refused by callers parsing through parse_sql, with a hint to raise a setting already raised.

Changes

  • Ranking rules: an OVER window name resolves against the SELECT's own WINDOW clause, then the enclosing ones, nearest first: those after parentheses and those of outer SELECTs, so a nearer definition of the same name wins, as in Spark. The ROW_NUMBER() = 1 key inference still reads only an inline OVER, as before.
  • Breaking: sqlquack_lint::parse_sql(sql, dialect) is now parse_sql(sql, dialect, max_function_call_depth: Option<usize>). None keeps the default of 256, and a value above 512 is refused as a lint request refuses it. There is no compatibility wrapper: every caller passes the new argument.

Verification

  • make check-ci on the final head.
  • Databricks cases for SQLCLEAN043 (with and without a WITH) and SQLCLEAN018 (unproven and proven) on a window after the parentheses, which fail on main, where the rules report nothing, plus a name defined at two levels.
  • parse_sql cases: 300 nested calls parse with Some(400), are refused with None at call 257, and a limit of 1000 is refused naming the ceiling of 512.
  • Lint library tests: 39 passed.

Databricks keeps a WINDOW clause written after a parenthesized query on
the subquery node, but the ranking rules looked a window name up only in
the SELECT's own WINDOW clause. SQLCLEAN018 and SQLCLEAN043 were
therefore silent for (SELECT ..., ROW_NUMBER() OVER w AS rn FROM orders)
WINDOW w AS (ORDER BY ...), with or without a WITH before the
parentheses.

An OVER name now resolves against the SELECT's own windows, then the
enclosing WINDOW clauses, nearest first: those after parentheses and
those of outer SELECTs whose FROM holds the query, so a nearer
definition of the same name wins, as in Spark. Databricks cases cover
both rules, the WITH form, a proven ordering and a name defined at two
levels. The key inference for ROW_NUMBER() = 1 dedups still reads only
an inline OVER, as before.
parse_sql always parsed within the default limit of 256 nested calls, so
SQL that a lint request with a raised max_function_call_depth accepted
was refused by callers that parse through parse_sql, with a hint to
raise a setting already raised.

parse_sql(sql, dialect, max_function_call_depth) now takes the limit:
None keeps the default, and a value above 512 is refused as a lint
request refuses it. This is breaking: every caller passes the new
argument.
@kvlonge
kvlonge enabled auto-merge November 18, 2026 21:08
@kvlonge
kvlonge added this pull request to the merge queue Nov 18, 2026
Merged via the queue into main with commit 4dd6098 Nov 18, 2026
9 checks passed
@kvlonge
kvlonge deleted the fix/lint-subquery-windows branch November 18, 2026 22:02
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