Skip to content

Commit

Permalink
Modifying Redshift USER/GROUP Statements To Use `ObjectReferenceSegme…
Browse files Browse the repository at this point in the history
…nt` (#2190)

* Adding needed unreserved keywords

* Adding needed unreserved keywords

* Modifying CreateUserStatement, AlterUserStatement, and CreateGroupSegment to use ObjectReferenceSegment instead of NakedIdentifierSegment

* Removing alter group

* Adding modified .yml files

* Fixing missing ObjectReferenceSegment

* Adding additional quoting tests

Co-authored-by: Barry Pollard <barry@tunetheweb.com>
  • Loading branch information
tdstark and tunetheweb committed Dec 26, 2021
1 parent 212432f commit e4fc70c
Show file tree
Hide file tree
Showing 10 changed files with 250 additions and 99 deletions.
18 changes: 9 additions & 9 deletions src/sqlfluff/dialects/dialect_redshift.py
Expand Up @@ -317,7 +317,7 @@ class CreateUserSegment(BaseSegment):
match_grammar = Sequence(
"CREATE",
"USER",
Ref("NakedIdentifierSegment"),
Ref("ObjectReferenceSegment"),
Ref.keyword("WITH", optional=True),
"PASSWORD",
OneOf(Ref("QuotedLiteralSegment"), "DISABLE"),
Expand All @@ -338,7 +338,7 @@ class CreateUserSegment(BaseSegment):
"UNRESTRICTED",
),
),
Sequence("IN", "GROUP", Delimited(Ref("NakedIdentifierSegment"))),
Sequence("IN", "GROUP", Delimited(Ref("ObjectReferenceSegment"))),
Sequence("VALID", "UNTIL", Ref("QuotedLiteralSegment")),
Sequence(
"CONNECTION",
Expand Down Expand Up @@ -369,12 +369,12 @@ class CreateGroupSegment(BaseSegment):
match_grammar = Sequence(
"CREATE",
"GROUP",
Ref("NakedIdentifierSegment"),
Ref("ObjectReferenceSegment"),
Sequence(
Ref.keyword("WITH", optional=True),
"USER",
Delimited(
Ref("NakedIdentifierSegment"),
Ref("ObjectReferenceSegment"),
),
optional=True,
),
Expand All @@ -393,7 +393,7 @@ class AlterUserSegment(BaseSegment):
match_grammar = Sequence(
"ALTER",
"USER",
Ref("NakedIdentifierSegment"),
Ref("ObjectReferenceSegment"),
Ref.keyword("WITH", optional=True),
AnyNumberOf(
OneOf(
Expand Down Expand Up @@ -423,7 +423,7 @@ class AlterUserSegment(BaseSegment):
Sequence(
"RENAME",
"TO",
Ref("NakedIdentifierSegment"),
Ref("ObjectReferenceSegment"),
),
Sequence(
"CONNECTION",
Expand All @@ -448,7 +448,7 @@ class AlterUserSegment(BaseSegment):
OneOf(
Sequence(
"SET",
Ref("NakedIdentifierSegment"),
Ref("ObjectReferenceSegment"),
OneOf(
"TO",
Ref("EqualsSegment"),
Expand All @@ -460,7 +460,7 @@ class AlterUserSegment(BaseSegment):
),
Sequence(
"RESET",
Ref("NakedIdentifierSegment"),
Ref("ObjectReferenceSegment"),
),
),
min_times=1,
Expand All @@ -480,7 +480,7 @@ class AlterGroupSegment(BaseSegment):
match_grammar = Sequence(
"ALTER",
"GROUP",
Ref("NakedIdentifierSegment"),
Ref("ObjectReferenceSegment"),
OneOf(
Sequence(
OneOf("ADD", "DROP"),
Expand Down
6 changes: 6 additions & 0 deletions src/sqlfluff/dialects/dialect_redshift_keywords.py
Expand Up @@ -202,6 +202,7 @@
ATTACH
ATTRIBUTE
ATTRIBUTES
AUTO_INCREMENT
AVG
BACKUP
BACKWARD
Expand Down Expand Up @@ -688,6 +689,7 @@
RECOVERY
RECURSIVE
REF
REFERENCE_USAGE
REFERENCING
REFRESH
REGR_AVGX
Expand Down Expand Up @@ -789,6 +791,7 @@
SQRT
STABLE
STAGE
STAGES
STANDALONE
START
STATE
Expand All @@ -802,6 +805,7 @@
STORAGE
STORED
STREAM
STREAMS
STRICT
STRING
STRIP
Expand Down Expand Up @@ -829,6 +833,7 @@
TAN
TANH
TASK
TASKS
TEMP
TEMPLATE
TEMPORARY
Expand Down Expand Up @@ -885,6 +890,7 @@
UPDATE
UPPER
URI
USE_ANY_ROLE
USAGE
USE
USER_DEFINED_TYPE_CATALOG
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/dialects/redshift/redshift_alter_group.sql
Expand Up @@ -13,3 +13,6 @@ rename to administrators;

alter group admin_group
add user "test.user";

alter group "admin_group"
add user "test.user";
31 changes: 24 additions & 7 deletions test/fixtures/dialects/redshift/redshift_alter_group.yml
Expand Up @@ -3,13 +3,14 @@
# 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: a538acbf3613b80cf16457e14adde74d70dfa28d3dab8192a28ebf75f15488b5
_hash: 029b318933b851dc01458231e585596fbeb48d071f477a903a5d5d51acf31e3e
file:
- statement:
alter_group:
- keyword: alter
- keyword: group
- identifier: admin_group
- object_reference:
identifier: admin_group
- keyword: add
- keyword: user
- object_reference:
Expand All @@ -19,7 +20,8 @@ file:
alter_group:
- keyword: alter
- keyword: group
- identifier: admin_group
- object_reference:
identifier: admin_group
- keyword: add
- keyword: user
- object_reference:
Expand All @@ -32,7 +34,8 @@ file:
alter_group:
- keyword: alter
- keyword: group
- identifier: admin_group
- object_reference:
identifier: admin_group
- keyword: drop
- keyword: user
- object_reference:
Expand All @@ -42,7 +45,8 @@ file:
alter_group:
- keyword: alter
- keyword: group
- identifier: admin_group
- object_reference:
identifier: admin_group
- keyword: drop
- keyword: user
- object_reference:
Expand All @@ -55,7 +59,8 @@ file:
alter_group:
- keyword: alter
- keyword: group
- identifier: admin_group
- object_reference:
identifier: admin_group
- keyword: rename
- keyword: to
- object_reference:
Expand All @@ -65,7 +70,19 @@ file:
alter_group:
- keyword: alter
- keyword: group
- identifier: admin_group
- object_reference:
identifier: admin_group
- keyword: add
- keyword: user
- object_reference:
identifier: '"test.user"'
- statement_terminator: ;
- statement:
alter_group:
- keyword: alter
- keyword: group
- object_reference:
identifier: '"admin_group"'
- keyword: add
- keyword: user
- object_reference:
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/dialects/redshift/redshift_alter_user.sql
Expand Up @@ -4,6 +4,9 @@ alter user admin with createdb;
alter user admin nocreatedb;
alter user admin with nocreatedb;

alter user "dbuser" reset var;
alter user "dbuser" with reset var;

alter user admin createuser;
alter user admin with createuser;

Expand Down

0 comments on commit e4fc70c

Please sign in to comment.