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

Redshift CREATE SCHEMA statements #2252

Merged
merged 5 commits into from
Jan 8, 2022

Conversation

rpr-ableton
Copy link
Contributor

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.html

Side 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 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.

Copy link
Contributor

@jpy-git jpy-git left a 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
Copy link
Contributor

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.

Comment on lines 405 to 411
Ref("IfNotExistsGrammar", optional=True),
Ref("SchemaReferenceSegment"),
Sequence(
"AUTHORIZATION",
Ref("ObjectReferenceSegment"),
optional=True,
),
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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
Copy link

codecov bot commented Jan 7, 2022

Codecov Report

Merging #2252 (7372508) into main (286a526) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##              main     #2252   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          156       156           
  Lines        11102     11106    +4     
=========================================
+ Hits         11102     11106    +4     
Impacted Files Coverage Δ
src/sqlfluff/dialects/dialect_redshift_keywords.py 100.00% <ø> (ø)
src/sqlfluff/dialects/dialect_redshift.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 286a526...7372508. Read the comment docs.

@jpy-git
Copy link
Contributor

jpy-git commented Jan 7, 2022

PS you need to need to run black to format your code.

Would recommend using the the pre-commit hook described here as it automatically takes care of these checks at commit time so you don't forget in the future 😄

@rpr-ableton
Copy link
Contributor Author

Thanks for the comments and pointers! 👍

I also have no clue what is hidden behind schema_element so I've marked it as TODO.

Copy link
Contributor

@jpy-git jpy-git left a 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 🚀 ✨

@jpy-git jpy-git merged commit 62859f1 into sqlfluff:main Jan 8, 2022
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.

2 participants