Repository navigation
fix(lint)!: resolve windows after parentheses and take a depth limit in parse_sql - #260
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Two lint gaps reach SQLClean.
WINDOWwritten 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 aWITHbefore the parentheses.parse_sqlalways parsed within the default limit of 256 nested calls. SQL that a lint request with a raisedmax_function_call_depthaccepted was refused by callers parsing throughparse_sql, with a hint to raise a setting already raised.Changes
OVERwindow name resolves against the SELECT's ownWINDOWclause, 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. TheROW_NUMBER() = 1key inference still reads only an inlineOVER, as before.sqlquack_lint::parse_sql(sql, dialect)is nowparse_sql(sql, dialect, max_function_call_depth: Option<usize>).Nonekeeps 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-cion the final head.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_sqlcases: 300 nested calls parse withSome(400), are refused withNoneat call 257, and a limit of 1000 is refused naming the ceiling of 512.