Repository navigation
fix(rules): read unparenthesised VALUES and UNPIVOT aliases as relations - #100
Merged
Merged
Conversation
SQLCLEAN029 reported v.a in FROM VALUES (1), (2) AS v(a), and u.k for an UNPIVOT aliased u, as qualifiers naming no relation in sight. The query scopes now name these items by their alias. SQLCLEAN023 keeps its earlier findings for them: a bare VALUES alias is not reported, and an UNPIVOT alias is still kept without a fix.
Deploying sqlclean with
|
| Latest commit: |
2993e1e
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://85aea82e.sqlclean.pages.dev |
| Branch Preview URL: | https://fix-values-alias-scope.sqlclean.pages.dev |
…s unflagged by SQLCLEAN027 SQLCLEAN027 reported three kinds of unqualified names that no relation alias can or should qualify: - a column merged by USING, such as k in FROM a FULL JOIN b USING (k), where a.k or b.k would read one side instead of the merged key; - the bare date part of LAST_DAY(d, month), whose position the date part table did not know (it only knew first arguments); - a macro parameter placeholder, which stands for whatever the caller passes. The lint corpus loses 027 findings on USING keys only.
SQLCLEAN016 compared an alias with its column by the dialect's resolved name, so on Snowflake ENTITY_ID AS entity_id was flagged although the alias changes the output column's name for any tool that names columns as written. The Rule now flags only an alias that copies its column's name exactly: same spelling, same case and same quoting, on every dialect (amount AS amount, "Bar" AS "Bar", t.amount AS amount). An alias that changes only the case or the quoting is left alone. PostgreSQL's tree folds unquoted names as it parses them, so there a case change between unquoted names still reads as a copy; a test pins this until the tree keeps names as written. The message reads "Expression is aliased to an exact copy of its name". The lint corpus loses 12 SQLCLEAN016 findings, each a case or quoting change; every other changed line differs only in its message hash.
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
SQLCLEAN029 flagged
v.ainSELECT v.a FROM VALUES (1), (2) AS v(a)and in an aliased UNPIVOT (FROM orders UNPIVOT (...) AS u, read asu.k) as a relation absent from the query, on every dialect that parses them. SQLQuack's query scopes left those items' aliases out (fixed in sqlstack-io/sqlquack#275); with them in, SQLCLEAN023 would have offered broken fixes, such as removingAS v(a).Changes
Verification
make check-cipassed (fensu, docs skill, fmt, clippy).cargo test -p sqlclean-lint -p sqlclean-rules(lint corpus included) andcargo test -p sqlclean --lib sql_lintpassed against the SQLQuack fix.