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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
45 changes: 45 additions & 0 deletions src/sqlfluff/dialects/dialect_redshift.py
Expand Up @@ -391,6 +391,51 @@ class InsertStatementSegment(BaseSegment):
)


@redshift_dialect.segment(replace=True)
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.

TODO: support optional SCHEMA_ELEMENT
"""

type = "create_schema_statement"
match_grammar = Sequence(
"CREATE",
"SCHEMA",
OneOf(
Sequence(
Ref("IfNotExistsGrammar", optional=True),
Ref("SchemaReferenceSegment"),
Sequence(
"AUTHORIZATION",
Ref("ObjectReferenceSegment"),
optional=True,
),
),
Sequence(
"AUTHORIZATION",
Ref("ObjectReferenceSegment"),
),
),
Sequence(
"QUOTA",
OneOf(
Sequence(
Ref("NumericLiteralSegment"),
OneOf(
"MB",
"GB",
"TB",
),
),
"UNLIMITED",
),
optional=True,
),
)


# Adding Redshift specific statements
@redshift_dialect.segment(replace=True)
class StatementSegment(BaseSegment):
Expand Down
4 changes: 4 additions & 0 deletions src/sqlfluff/dialects/dialect_redshift_keywords.py
Expand Up @@ -432,6 +432,7 @@
FUSION
FUTURE
G
GB
GENERAL
GENERATED
GET
Expand Down Expand Up @@ -545,6 +546,7 @@
MATERIALIZED
MAX
MAXVALUE
MB
MEASURES
MEMBER
MERGE
Expand Down Expand Up @@ -686,6 +688,7 @@
PUBLICATION
QUALIFY
QUARTER
QUOTA
QUOTE
QUOTES
RANGE
Expand Down Expand Up @@ -845,6 +848,7 @@
TANH
TASK
TASKS
TB
TEMP
TEMPLATE
TEMPORARY
Expand Down
27 changes: 27 additions & 0 deletions test/fixtures/dialects/redshift/redshift_create_schema.sql
@@ -0,0 +1,27 @@
CREATE SCHEMA s1;
CREATE SCHEMA IF NOT EXISTS s1;

CREATE SCHEMA s1 AUTHORIZATION dwuser;
CREATE SCHEMA IF NOT EXISTS s1 AUTHORIZATION dwuser;

CREATE SCHEMA s1 AUTHORIZATION dwuser QUOTA 100 MB;
CREATE SCHEMA IF NOT EXISTS s1 AUTHORIZATION dwuser QUOTA 100 MB;

CREATE SCHEMA s1 AUTHORIZATION dwuser QUOTA 5 GB;
CREATE SCHEMA IF NOT EXISTS s1 AUTHORIZATION dwuser QUOTA 5 GB;

CREATE SCHEMA s1 AUTHORIZATION dwuser QUOTA 0.1 TB;
CREATE SCHEMA IF NOT EXISTS s1 AUTHORIZATION dwuser QUOTA 0.1 TB;

CREATE SCHEMA s1 AUTHORIZATION dwuser QUOTA UNLIMITED;
CREATE SCHEMA IF NOT EXISTS s1 AUTHORIZATION dwuser QUOTA UNLIMITED;

CREATE SCHEMA AUTHORIZATION dwuser;

CREATE SCHEMA AUTHORIZATION dwuser QUOTA 100 MB;

CREATE SCHEMA AUTHORIZATION dwuser QUOTA 5 GB;

CREATE SCHEMA AUTHORIZATION dwuser QUOTA 0.1 TB;

CREATE SCHEMA AUTHORIZATION dwuser QUOTA UNLIMITED;
212 changes: 212 additions & 0 deletions test/fixtures/dialects/redshift/redshift_create_schema.yml
@@ -0,0 +1,212 @@
# YML test files are auto-generated from SQL files and should not be edited by
# hand. To help enforce this, the "hash" field in the file must match a hash
# computed by SQLFluff when running the tests. Please run
# `python test/generate_parse_fixture_yml.py` to generate them after adding or
# altering SQL files.
_hash: 9c60d7f03836f977999a5ad56c70f44448fef6e0cadd94dfe772a82624f91e41
file:
- statement:
create_schema_statement:
- keyword: CREATE
- keyword: SCHEMA
- schema_reference:
identifier: s1
- statement_terminator: ;
- statement:
create_schema_statement:
- keyword: CREATE
- keyword: SCHEMA
- keyword: IF
- keyword: NOT
- keyword: EXISTS
- schema_reference:
identifier: s1
- statement_terminator: ;
- statement:
create_schema_statement:
- keyword: CREATE
- keyword: SCHEMA
- schema_reference:
identifier: s1
- keyword: AUTHORIZATION
- object_reference:
identifier: dwuser
- statement_terminator: ;
- statement:
create_schema_statement:
- keyword: CREATE
- keyword: SCHEMA
- keyword: IF
- keyword: NOT
- keyword: EXISTS
- schema_reference:
identifier: s1
- keyword: AUTHORIZATION
- object_reference:
identifier: dwuser
- statement_terminator: ;
- statement:
create_schema_statement:
- keyword: CREATE
- keyword: SCHEMA
- schema_reference:
identifier: s1
- keyword: AUTHORIZATION
- object_reference:
identifier: dwuser
- keyword: QUOTA
- literal: '100'
- keyword: MB
- statement_terminator: ;
- statement:
create_schema_statement:
- keyword: CREATE
- keyword: SCHEMA
- keyword: IF
- keyword: NOT
- keyword: EXISTS
- schema_reference:
identifier: s1
- keyword: AUTHORIZATION
- object_reference:
identifier: dwuser
- keyword: QUOTA
- literal: '100'
- keyword: MB
- statement_terminator: ;
- statement:
create_schema_statement:
- keyword: CREATE
- keyword: SCHEMA
- schema_reference:
identifier: s1
- keyword: AUTHORIZATION
- object_reference:
identifier: dwuser
- keyword: QUOTA
- literal: '5'
- keyword: GB
- statement_terminator: ;
- statement:
create_schema_statement:
- keyword: CREATE
- keyword: SCHEMA
- keyword: IF
- keyword: NOT
- keyword: EXISTS
- schema_reference:
identifier: s1
- keyword: AUTHORIZATION
- object_reference:
identifier: dwuser
- keyword: QUOTA
- literal: '5'
- keyword: GB
- statement_terminator: ;
- statement:
create_schema_statement:
- keyword: CREATE
- keyword: SCHEMA
- schema_reference:
identifier: s1
- keyword: AUTHORIZATION
- object_reference:
identifier: dwuser
- keyword: QUOTA
- literal: '0.1'
- keyword: TB
- statement_terminator: ;
- statement:
create_schema_statement:
- keyword: CREATE
- keyword: SCHEMA
- keyword: IF
- keyword: NOT
- keyword: EXISTS
- schema_reference:
identifier: s1
- keyword: AUTHORIZATION
- object_reference:
identifier: dwuser
- keyword: QUOTA
- literal: '0.1'
- keyword: TB
- statement_terminator: ;
- statement:
create_schema_statement:
- keyword: CREATE
- keyword: SCHEMA
- schema_reference:
identifier: s1
- keyword: AUTHORIZATION
- object_reference:
identifier: dwuser
- keyword: QUOTA
- keyword: UNLIMITED
- statement_terminator: ;
- statement:
create_schema_statement:
- keyword: CREATE
- keyword: SCHEMA
- keyword: IF
- keyword: NOT
- keyword: EXISTS
- schema_reference:
identifier: s1
- keyword: AUTHORIZATION
- object_reference:
identifier: dwuser
- keyword: QUOTA
- keyword: UNLIMITED
- statement_terminator: ;
- statement:
create_schema_statement:
- keyword: CREATE
- keyword: SCHEMA
- keyword: AUTHORIZATION
- object_reference:
identifier: dwuser
- statement_terminator: ;
- statement:
create_schema_statement:
- keyword: CREATE
- keyword: SCHEMA
- keyword: AUTHORIZATION
- object_reference:
identifier: dwuser
- keyword: QUOTA
- literal: '100'
- keyword: MB
- statement_terminator: ;
- statement:
create_schema_statement:
- keyword: CREATE
- keyword: SCHEMA
- keyword: AUTHORIZATION
- object_reference:
identifier: dwuser
- keyword: QUOTA
- literal: '5'
- keyword: GB
- statement_terminator: ;
- statement:
create_schema_statement:
- keyword: CREATE
- keyword: SCHEMA
- keyword: AUTHORIZATION
- object_reference:
identifier: dwuser
- keyword: QUOTA
- literal: '0.1'
- keyword: TB
- statement_terminator: ;
- statement:
create_schema_statement:
- keyword: CREATE
- keyword: SCHEMA
- keyword: AUTHORIZATION
- object_reference:
identifier: dwuser
- keyword: QUOTA
- keyword: UNLIMITED
- statement_terminator: ;