Skip to content
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

L027 bizarre log output: "Unqualified reference '\\n *' found in select" #1668

Closed
barrywhart opened this issue Oct 15, 2021 · 4 comments
Closed
Labels
bug Something isn't working rule bug A rule is not working as intended, either missing errors or incorrectly highlighting non-errors

Comments

@barrywhart
Copy link
Member

Expected Behaviour

Observed Behaviour

Run this command:

sqlfluff fix test.sql -vvvv --exclude-rules L031 --force

On this file:

SELECT * FROM id_map AS i JOIN building_structure AS s ON i.building_id = s.building_id WHERE district_id = 3 LIMIT 5

The log output includes text:
DEBUG [L027] !! Violation Found: "Unqualified reference '\n *' found in select with more than one referenced table/view."

This is at best a bug in L027, but seeing a "reference" including newline and whitespace makes me wonder if there's a lexer or parser issue as well.

Steps to Reproduce

Dialect

Version

Include the output of sqlfluff --version along with your Python version

Configuration

Include your SQLFluff configuration here
@barrywhart barrywhart added the bug Something isn't working label Oct 15, 2021
@barrywhart
Copy link
Member Author

The input file has no newlines. Thus, the newline is likely coming from a rule fix. Looking through the logs, I think I can confirm this. See this log excerpt:

INFO       0 -> 'SELECT * FROM id_map AS i JOIN building_structure AS s ON i.building_id = s.building_id WHERE district_id = 3 LIMIT 5\n'
DEBUG      [L016] !! Violation Found: 'Line is too long'
DEBUG      [L016] !! Fix Proposed: <LintFix: delete @[L:  1, P:  7] delete:' '>
DEBUG      [L016] !! Fix Proposed: <LintFix: create @[L:  1, P:  8] create:'\n    '>
DEBUG      [L016] !! Fix Proposed: <LintFix: delete @[L:  1, P:  9] delete:' '>
DEBUG      [L016] !! Fix Proposed: <LintFix: create @[L:  1, P: 10] create:'\n'>
INFO       Applying Fixes [L016]: [<LintFix: delete @[L:  1, P:  7] delete:' '>, <LintFix: create @[L:  1, P:  8] create:'\n    '>, <LintFix: delete @[L:  1, P:  9] delete:' '>, <LintFix: create @[L:  1, P: 10] create:'\n'>]
DEBUG      Matched fix against segment: <LintFix: delete @[L:  1, P:  9] delete:' '> -> <WhitespaceSegment: ([L:  1, P:  9]) ' '>
DEBUG      Matched fix against segment: <LintFix: delete @[L:  1, P:  7] delete:' '> -> <WhitespaceSegment: ([L:  1, P:  7]) ' '>
DEBUG      Matched fix against segment: <LintFix: create @[L:  1, P:  8] create:'\n    '> -> <SymbolSegment: ([L:  1, P:  8]) '*'>
DEBUG      Matched fix against segment: <LintFix: create @[L:  1, P: 10] create:'\n'> -> <KeywordSegment: ([L:  1, P: 10]) 'FROM'>
DEBUG      [L027] !! Violation Found: "Unqualified reference '\\n    *' found in select with more than one referenced table/view."
DEBUG      [L027] !! Violation Found: "Unqualified reference '\\n    *' found in select with more than one referenced table/view."
DEBUG      [L027] !! Violation Found: "Unqualified reference 'district_id' found in select with more than one referenced table/view."

So the L016 fixes are probably causing something weird.

@barrywhart
Copy link
Member Author

I examined the segments involved at the time L027 reports the issue.

(Pdb) !r
<WildcardIdentifierSegment: ([L:  1, P:  8])>
(Pdb) !r.segments
(<NewlineSegment: ([L:  1, P:  8]) '\n'>, <WhitespaceSegment: ([L:  1, P:  8]) '    '>, <SymbolSegment: ([L:  1, P:  8]) '*'>)

If I modify test.sql so L016 didn't need to split the line, e.g.

Now L027 still detects an issue, but the WildcardIdentifierSegment only has one child.

(Pdb) !r
<WildcardIdentifierSegment: ([L:  2, P:  5])>
(Pdb) !r.segments
(<SymbolSegment: ([L:  2, P:  5]) '*'>,)

@barrywhart barrywhart added the rule bug A rule is not working as intended, either missing errors or incorrectly highlighting non-errors label Oct 16, 2021
@barrywhart
Copy link
Member Author

This issue looks like another occurrence of #1304.

@tunetheweb
Copy link
Member

Tested this on latest main and don't get that any more.

Do get a few others, but think it's right they are there:

% sqlfluff fix test.sql -vvvv --exclude-rules L031 --force | grep "ound in select with more than one refere"
DEBUG      [L027] !! Violation Found: "Unqualified reference '*' found in select with more than one referenced table/view."                                                                                                                             
DEBUG      [L027] !! Violation Found: "Unqualified reference 'district_id' found in select with more than one referenced table/view."                        

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working rule bug A rule is not working as intended, either missing errors or incorrectly highlighting non-errors
Projects
None yet
Development

No branches or pull requests

2 participants