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

Fix subquery bug in L026 #1948

Merged
merged 4 commits into from Nov 22, 2021
Merged

Fix subquery bug in L026 #1948

merged 4 commits into from Nov 22, 2021

Conversation

jpy-git
Copy link
Contributor

@jpy-git jpy-git commented Nov 20, 2021

Brief summary of the change made

This PR fixes bug in L026 in which table references within subqueries were incorrectly being identified as not being found. Fixes #1939.

On investigating I found the cause was the references returned from get_select_statement_info incorrectly included references from subqueries. There was already some logic in get_select_statement_info to handle this but was in the wrong place in the function. I have moved this logic to the end of the function and added extra unit tests to all rules which utilise get_select_statement_info to provide additional validation.

Are there any other side effects of this change that we should be aware of?

Not that I'm aware of, I've added additional unit tests to be sure that other rules aren't impacted.

Pull Request checklist

  • Please confirm you have completed any of the necessary steps below.

  • Included test cases to demonstrate any code changes, which may be one or more of the following:

    • .yml rule test cases in test/fixtures/rules/std_rule_cases.
    • .sql/.yml parser test cases in test/fixtures/dialects (note YML files can be auto generated with python test/generate_parse_fixture_yml.py or by running tox locally).
    • Full autofix test cases in test/fixtures/linter/autofix.
    • Other.
  • Added appropriate documentation for the change.

  • Created GitHub issues for any relevant followup/future enhancements if appropriate.

Copy link
Member

@tunetheweb tunetheweb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM if the tests pass.

@pwildenhain too late to get into 0.8.2? Will let you merge if you're happy to include. If not will merge after.

@codecov
Copy link

codecov bot commented Nov 20, 2021

Codecov Report

Merging #1948 (e162c65) into main (14f93b3) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##              main     #1948   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          147       147           
  Lines        10219     10219           
=========================================
  Hits         10219     10219           
Impacted Files Coverage Δ
src/sqlfluff/core/rules/analysis/select.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 14f93b3...e162c65. Read the comment docs.

@pwildenhain pwildenhain mentioned this pull request Nov 21, 2021
@tunetheweb
Copy link
Member

Does this fix #1462 as well out of interest?

Happy to merge as is but thought worth asking if it does, or if it’s related and could be made to, before I merge.

@jpy-git
Copy link
Contributor Author

jpy-git commented Nov 21, 2021

Will take a look into it 👀

@jpy-git
Copy link
Contributor Author

jpy-git commented Nov 21, 2021

@tunetheweb I've checked and no it doesn't seem to impact that issue so I think we can consider it out of scope for this PR. Let's merge this one in and then happy to investigate the other issue further seperately 😄

@tunetheweb tunetheweb merged commit 9ebbd03 into sqlfluff:main Nov 22, 2021
@jpy-git jpy-git deleted the L026_subquery_bug branch November 22, 2021 09:27
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.

L026 rule (ansi) cannot find table/view aliases in the FROM clause with JOINS in subquery
2 participants