-
-
Notifications
You must be signed in to change notification settings - Fork 750
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
Redshift CREATE SCHEMA statements #2252
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work @rpr-ableton! Couple things to address but otherwise great 😄
class CreateSchemaStatementSegment(BaseSegment): | ||
"""A `CREATE SCHEMA` statement. | ||
|
||
https://docs.aws.amazon.com/redshift/latest/dg/r_CREATE_SCHEMA.html |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at the docs there's a bit missing from the end of the grammar here:
[ schema_element [ ... ]
The docs aren't very clear for me as to what exactly they represent but if you're familiar with them then would be good to add them in.
If not then just add a TODO note to the end of the docstring mentioning that we haven't added this.
Ref("IfNotExistsGrammar", optional=True), | ||
Ref("SchemaReferenceSegment"), | ||
Sequence( | ||
"AUTHORIZATION", | ||
Ref("ObjectReferenceSegment"), | ||
optional=True, | ||
), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ref("IfNotExistsGrammar", optional=True), | |
Ref("SchemaReferenceSegment"), | |
Sequence( | |
"AUTHORIZATION", | |
Ref("ObjectReferenceSegment"), | |
optional=True, | |
), | |
OneOf( | |
Sequence( | |
Ref("IfNotExistsGrammar", optional=True), | |
Ref("SchemaReferenceSegment"), | |
Sequence( | |
"AUTHORIZATION", | |
Ref("ObjectReferenceSegment"), | |
optional=True, | |
), | |
), | |
Sequence( | |
"AUTHORIZATION", | |
Ref("ObjectReferenceSegment"), | |
), | |
), |
looking at the docs your grammar corresponds to the first statement variation:
CREATE SCHEMA [ IF NOT EXISTS ] schema_name [ AUTHORIZATION username ]
[ QUOTA {quota [MB | GB | TB] | UNLIMITED} ] [ schema_element [ ... ]
However there's another variant below that:
CREATE SCHEMA AUTHORIZATION username[ QUOTA {quota [MB | GB | TB] | UNLIMITED} ] [ schema_element [ ... ] ]
Think this suggestion should cover that case. Would you be able to add the relevant test case to verify this as well 😄
Codecov Report
@@ Coverage Diff @@
## main #2252 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 156 156
Lines 11102 11106 +4
=========================================
+ Hits 11102 11106 +4
Continue to review full report at Codecov.
|
PS you need to need to run black to format your code. Would recommend using the the |
Thanks for the comments and pointers! 👍 I also have no clue what is hidden behind |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rpr-ableton great first contribution, thanks! LGTM 🚀 ✨
Brief summary of the change made
Features:
Ensure that SQLFluff can parse
CREATE SCHEMA
statements as defined in Redshift documentation here: https://docs.aws.amazon.com/redshift/latest/dg/r_CREATE_SCHEMA.htmlSide note:
This is my first contribution and I was not sure if I should open an issue first before making the changes. If so, please let me know and I'll be happy to create an issue and update this PR to add the link to it.
Also since this a first, I might have missed some gotchas, just let me know! Thanks!
Are there any other side effects of this change that we should be aware of?
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 intest/fixtures/rules/std_rule_cases
..sql
/.yml
parser test cases intest/fixtures/dialects
(note YML files can be auto generated withtox -e generate-fixture-yml
).test/fixtures/linter/autofix
.Added appropriate documentation for the change.
Created GitHub issues for any relevant followup/future enhancements if appropriate.