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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix L022 to not flag CTE column definitions #2139

Merged
merged 4 commits into from Dec 19, 2021
Merged

Fix L022 to not flag CTE column definitions #2139

merged 4 commits into from Dec 19, 2021

Conversation

jpy-git
Copy link
Contributor

@jpy-git jpy-git commented Dec 19, 2021

Brief summary of the change made

Fixes #2136. L022 currently uses closing bracket to find the end of a CTE. This is fine for most cases but unintentionally flags CTE column definitions as described in the linked issue. Fix is simple: Check that the preceding keyword to the bracketed segment is AS 馃憣

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

No

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.

@codecov
Copy link

codecov bot commented Dec 19, 2021

Codecov Report

Merging #2139 (7022f95) into main (0b58b83) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##              main     #2139   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          148       148           
  Lines        10677     10679    +2     
=========================================
+ Hits         10677     10679    +2     
Impacted Files Coverage 螖
src/sqlfluff/rules/L022.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 0b58b83...7022f95. Read the comment docs.

Copy link
Member

@barrywhart barrywhart left a comment

Choose a reason for hiding this comment

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

Looks good! 馃憤

@jpy-git jpy-git merged commit 897fba8 into sqlfluff:main Dec 19, 2021
@jpy-git jpy-git deleted the l022_cte_column_definition branch December 19, 2021 22:53
@tunetheweb
Copy link
Member

It looks related but slightly different.

This issue fixed the original test case, and also fixes yours if the (var) is set on cte_1 but not for cte_2.

Let's keep this closed, and can you open a new issue for that? Link to this PR in that.

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.

CTE with column names is handled incorrectly in lint and fix
3 participants