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

L031 - Avoid using aliases in join coditions #473

Conversation

piotrgredowski
Copy link
Contributor

@piotrgredowski piotrgredowski commented Oct 7, 2020

This is just a WIP PR for #469
Just wanted to ask if it is good approach to solve presented problem :)
There is a lot to improve - especially docstrings, SQL file name etc. But yeah. It's just a start :)

@piotrgredowski piotrgredowski force-pushed the avoid-using-aliases-in-join-conditions branch 2 times, most recently from bf28fe5 to 9689b86 Compare October 7, 2020 20:58
@alanmcruickshank
Copy link
Member

alanmcruickshank commented Oct 7, 2020

Hi @piotrgredowski , thanks for getting involved.

A few tips on your approach:

  • I think given you're overriding _lint_references_and_aliases and _eval, I don't think you need to inherit from Rule_L025 and you can just inherit from BaseCrawler and have a nice clean rule to work with.
  • Rather than list(seg.recursive_crawl('identifier')), I wonder if you can leverage the AliasExpressionSegment and look for an element of type alias_expression explicitly to avoid just assuming the identifiers will come in the right order. Although I'm not sure I can think of a scenario where they wouldn't at the moment. 🤔
  • Consider how you might implement a fix solution for this rule too. You can probably get some inspiration from the other rules which already exist but feel free to ask for tips here if you need!

@pwildenhain pwildenhain linked an issue Oct 7, 2020 that may be closed by this pull request
@piotrgredowski piotrgredowski force-pushed the avoid-using-aliases-in-join-conditions branch 2 times, most recently from ef1cec3 to e1b16be Compare October 7, 2020 23:01
@codecov
Copy link

codecov bot commented Oct 7, 2020

Codecov Report

Merging #473 into master will increase coverage by 0.07%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #473      +/-   ##
==========================================
+ Coverage   92.62%   92.70%   +0.07%     
==========================================
  Files          29       29              
  Lines        4708     4754      +46     
==========================================
+ Hits         4361     4407      +46     
  Misses        347      347              
Flag Coverage Δ
#py35 92.58% <100.00%> (+0.07%) ⬆️
#py36 92.58% <100.00%> (+0.07%) ⬆️
#py37 92.58% <100.00%> (+0.07%) ⬆️
#py38 92.53% <100.00%> (+0.07%) ⬆️
#py39 92.53% <100.00%> (+0.07%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/sqlfluff/rules/std.py 94.21% <100.00%> (+0.28%) ⬆️

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 aa1bb1c...bdba7c5. Read the comment docs.

@piotrgredowski
Copy link
Contributor Author

piotrgredowski commented Oct 7, 2020

This is very dirty version, returning too many LintResults for all edits/deletions - it (and many other things) will be refactored and fixed later (probably today). :)
I've implemented a fix too. But I couldn't find any test case for LintFixes. Am I blind? @alanmcruickshank can you show me some example? :)

edit: nevermind. I've found tests for LintFix :)

@piotrgredowski piotrgredowski force-pushed the avoid-using-aliases-in-join-conditions branch 2 times, most recently from 268173d to f89f5a1 Compare October 8, 2020 17:58
@piotrgredowski piotrgredowski force-pushed the avoid-using-aliases-in-join-conditions branch from f89f5a1 to 09bfe2e Compare October 8, 2020 18:02
@piotrgredowski piotrgredowski marked this pull request as ready for review October 8, 2020 18:49
@piotrgredowski
Copy link
Contributor Author

I've added support for self-joins too.

@piotrgredowski piotrgredowski changed the title WIP Avoid using aliases in join coditions Avoid using aliases in join coditions Oct 8, 2020
@NiallRees
Copy link
Member

Hey @piotrgredowski this is really cool, nice job with the fix implementation too. I'm going to approve but defer to @alanmcruickshank to merge as he had a few questions above (which I'm 99% sure you've addressed).

Copy link
Member

@NiallRees NiallRees left a comment

Choose a reason for hiding this comment

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

Thank you!

Copy link
Member

@alanmcruickshank alanmcruickshank left a comment

Choose a reason for hiding this comment

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

Thanks for this @piotrgredowski ! Very neat PR, good work on the fix, excellent test coverage. 👍

I've got a broader question about whether we should also have a rule against initialisms in aliases for tables in a FROM clause. I think that's a vagueness in the fishtown style guide rather than a problem with the work you've done though. I'll raise a separate issue for it.

@alanmcruickshank alanmcruickshank merged commit 1b23623 into sqlfluff:master Oct 10, 2020
@NiallRees NiallRees changed the title Avoid using aliases in join coditions L031 - Avoid using aliases in join coditions Nov 10, 2020
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.

Avoid table aliases in join conditions (especially initialisms)
3 participants