-
-
Notifications
You must be signed in to change notification settings - Fork 651
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
L025 rule firing in fix (but not lint) and breaking SQL for BigQuery UNNEST statement. #1302
Comments
Oh and one more piece of information. Once the indentation is fixed, |
I don't know exactly, but UNNEST is an odd construct. The rule probably only understands regular old table syntax. |
Except it doesn’t complain about it when indentation is corrected as per my follow up comment:
But yeah I agree |
Also, working on lint rules in SQLFluff is a very different experience than working on the dialects. Chaos vs order. Alchemy vs science. Rewarding, though. |
Challenge accepted! So going with the tried and tested method of throwing a lot of It all boiled down to this statement: sqlfluff/src/sqlfluff/core/rules/analysis/select.py Lines 134 to 137 in b97c2e4
When the spacing was added by the other rule, this resulted in the function name changing from "UNEST" to " UNEST" (with lots of spaces before the I'm not sure that adding spacing should technically change the function name, and whether that does (or will) cause any other issues, but the simplest fix here is to add a
Did a search for any other instances of Rewarding indeed to find that! |
Consider the following SQL in BigQuery dialect:
If I
lint
it, it correct picks up that theUNNEST
statement has bad indentation (should be the same indentation astable1
):However if I run
fix
on this it identifies two errors:The alias
category
IS being used - so why doesfix
think it's not being used? And why is it different than whatlint
found? I think it's because it seesUNNEST
as a table and thinks thecategory
is a table alias rather than a special column alias just forUNNEST
?And if I then
fix
this, it (correctly!) fixes the indentation but (incorrectly!) removes thecategory
alias:This breaks the query as the
category
in theSELECT
clause now refers to nothing!So it's almost like
fix
for rule L025 is not aware of this special syntax for BigQuery butlint
is?What's even stranger (and might point us in the direction of the fix) is that if I lint it without passing a dialect (so using the standard ANSI dialect) then even
lint
picks up the "error":Expected Behaviour
Fix should not attempt to fix non-linting errors and shouldn't break the SQL.
Observed Behaviour
Fix broke the SQL.
fix
identifying more issues thanlint
was also identified in #1149 but have opened this as a separate issue as it's a more specific example and that issue didn't say whether fix would break something or not.Steps to Reproduce
As per above
Dialect
BigQuery
Version
Include the output of
sqlfluff --version
along with your Python versionsqlfluff, version 0.6.3
Configuration
No config (other than
--dialect bigquery
in command line), so default.Will try to figure out what's going on here, and submit a fix if I do, but any pointers greatly appreciated as bit confused how
lint
andfix
can be different...The text was updated successfully, but these errors were encountered: