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

Support TRIM function parameters #3007

Merged
merged 4 commits into from Apr 5, 2022

Conversation

tunetheweb
Copy link
Member

Brief summary of the change made

Fixes #1935

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

These seem to be supported in many dialects. For those that don't support this I've overridden the Grammar to Nothing() to prevent it trying to find Keywords that don't exist.

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 tox -e generate-fixture-yml).
    • 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 Apr 5, 2022

Codecov Report

Merging #3007 (0ad10f6) into main (e8af773) will increase coverage by 0.05%.
The diff coverage is n/a.

@@             Coverage Diff             @@
##             main     #3007      +/-   ##
===========================================
+ Coverage   99.94%   100.00%   +0.05%     
===========================================
  Files         164       164              
  Lines       11981     11997      +16     
===========================================
+ Hits        11974     11997      +23     
+ Misses          7         0       -7     
Impacted Files Coverage Δ
src/sqlfluff/dialects/dialect_ansi.py 100.00% <ø> (ø)
src/sqlfluff/dialects/dialect_bigquery.py 100.00% <ø> (ø)
src/sqlfluff/dialects/dialect_hive.py 100.00% <ø> (ø)
src/sqlfluff/dialects/dialect_snowflake.py 100.00% <ø> (ø)
src/sqlfluff/dialects/dialect_tsql.py 100.00% <ø> (ø)
src/sqlfluff/rules/L004.py 100.00% <0.00%> (ø)
src/sqlfluff/rules/L016.py 100.00% <0.00%> (ø)
src/sqlfluff/core/parser/lexer.py 100.00% <0.00%> (ø)
src/sqlfluff/core/templaters/base.py 100.00% <0.00%> (ø)
src/sqlfluff/core/parser/grammar/base.py 100.00% <0.00%> (ø)
... and 10 more

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 e8af773...0ad10f6. Read the comment docs.

bracketed:
- start_bracket: (
- expression:
column_reference:
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it an issue that these are appearing as column references?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good spot. That shouldn't happen. Looking...

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.

One question about whether to allow these new parameters with function names other than TRIM. Overall, looks good.

@@ -943,6 +944,13 @@ class QualifiedNumericLiteralSegment(BaseSegment):
Ref("ExpressionSegment"),
# A Cast-like function
Sequence(Ref("ExpressionSegment"), "AS", Ref("DatatypeSegment")),
# Trim function
Sequence(
Copy link
Member

Choose a reason for hiding this comment

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

Are we checking the function name, or can this be used with any function? Seems like the latter. Any concerns with allowing that?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah I thought about that. You're right we do allow with any function. But very specific set of syntax and grammar so think will only match that.

This who FunctionContentsGrammar is made up of lots of syntax types that could be specific to certain function names but isn't, and this PR continues that theme.

To limit it to certain function names would require a change similar to #3004 where we get around it being a keyword (so it's still a function name type). But that gets messy and potentially unmaintainable pretty quickly. Hence I did initially implement #3004 in a similar manner to this. However, as that was specific to BigQuery, and similar to another pattern in Function I changed my mind on that.

For this TRIM one, I think we follow the previous pattern, as more generic and unlikely to match incorrectly.

@tunetheweb tunetheweb merged commit c74acba into sqlfluff:main Apr 5, 2022
@tunetheweb tunetheweb deleted the 1935-support-trim-function branch June 23, 2022 10:17
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.

Parsing issues with Spark trim command for both/leading/trailing
3 participants