Skip to content

Commit

Permalink
Snowflake: ALTER STORAGE INTEGRATION segment (#4406)
Browse files Browse the repository at this point in the history
  • Loading branch information
jared-rimmer committed Feb 19, 2023
1 parent 41e09a4 commit b0b87c0
Show file tree
Hide file tree
Showing 3 changed files with 674 additions and 0 deletions.
99 changes: 99 additions & 0 deletions src/sqlfluff/dialects/dialect_snowflake.py
Original file line number Diff line number Diff line change
Expand Up @@ -1010,6 +1010,7 @@ class StatementSegment(ansi.StatementSegment):
Ref("RemoveStatementSegment"),
Ref("CreateDatabaseFromShareStatementSegment"),
Ref("AlterRoleStatementSegment"),
Ref("AlterStorageIntegrationSegment"),
],
remove=[
Ref("CreateIndexStatementSegment"),
Expand Down Expand Up @@ -1968,6 +1969,104 @@ class AlterShareStatementSegment(BaseSegment):
)


class AlterStorageIntegrationSegment(BaseSegment):
"""An `ALTER STORAGE INTEGRATION` statement.
https://docs.snowflake.com/en/sql-reference/sql/alter-storage-integration
"""

type = "alter_storage_integration_statement"

match_grammar = Sequence(
"ALTER",
Ref.keyword("STORAGE", optional=True),
"INTEGRATION",
Ref("IfExistsGrammar", optional=True),
Ref("ObjectReferenceSegment"),
OneOf(
Sequence(
"SET",
OneOf(
Ref("TagEqualsSegment", optional=True),
AnySetOf(
Sequence(
"COMMENT", Ref("EqualsSegment"), Ref("QuotedLiteralSegment")
),
Sequence(
"ENABLED",
Ref("EqualsSegment"),
Ref("BooleanLiteralGrammar"),
),
OneOf(
AnySetOf(
Sequence(
"STORAGE_AWS_ROLE_ARN",
Ref("EqualsSegment"),
Ref("QuotedLiteralSegment"),
),
Sequence(
"STORAGE_AWS_OBJECT_ACL",
Ref("EqualsSegment"),
Ref("QuotedLiteralSegment"),
),
),
AnySetOf(
Sequence(
"AZURE_TENANT_ID",
Ref("EqualsSegment"),
Ref("QuotedLiteralSegment"),
),
),
),
Sequence(
"STORAGE_ALLOWED_LOCATIONS",
Ref("EqualsSegment"),
OneOf(
Bracketed(
Delimited(
OneOf(
Ref("S3Path"),
Ref("GCSPath"),
Ref("AzureBlobStoragePath"),
)
)
),
Bracketed(
Ref("QuotedStarSegment"),
),
),
),
Sequence(
"STORAGE_BLOCKED_LOCATIONS",
Ref("EqualsSegment"),
Bracketed(
Delimited(
OneOf(
Ref("S3Path"),
Ref("GCSPath"),
Ref("AzureBlobStoragePath"),
)
)
),
),
),
),
),
Sequence(
"UNSET",
OneOf(
Sequence(
"TAG", Delimited(Ref("TagReferenceSegment")), optional=True
),
"COMMENT",
"ENABLED",
"STORAGE_BLOCKED_LOCATIONS",
),
),
),
)


class AlterExternalTableStatementSegment(BaseSegment):
"""An `ALTER EXTERNAL TABLE` statement.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
alter storage integration test_integration set
tag tag1 = 'value1';

alter storage integration test_integration set
tag tag1 = 'value1', tag2 = 'value2';

alter storage integration test_integration
set comment = 'test comment';

alter storage integration test_integration unset
comment;

alter storage integration test_integration unset
tag tag1, tag2;

alter storage integration if exists test_integration unset
tag tag1, tag2;

alter storage integration test_integration unset
enabled;

alter storage integration test_integration unset
comment;

alter storage integration test_integration unset
storage_blocked_locations;

alter storage integration test_integration set
enabled = true;

alter storage integration test_integration
set enabled = false
comment = 'test comment';

alter storage integration test_integration set
comment = 'test comment'
enabled = false;

alter storage integration test_integration set
storage_aws_role_arn = 'test_role_arn';

alter storage integration test_integration set
storage_aws_object_acl = 'test_object_acl';

alter storage integration test_integration set
azure_tenant_id = 'test_azure_tenant_id';

alter storage integration s3_int set
storage_aws_role_arn = 'arn:aws:iam::001234567890:role/myrole'
enabled = true
storage_allowed_locations = (
's3://mybucket1', 's3://mybucket2/'
);

alter storage integration gcs_int set
enabled = true
storage_allowed_locations = (
'gcs://mybucket1/path1/',
'gcs://mybucket2/path2/'
);

alter storage integration azure_int set
enabled = true
azure_tenant_id = 'a123b4c5-1234-123a-a12b-1a23b45678c9'
storage_allowed_locations = (
'azure://myaccount.blob.core.windows.net/mycontainer/path1/',
'azure://myaccount.blob.core.windows.net/mycontainer/path2/'
);

alter storage integration s3_int set
storage_aws_role_arn = 'arn:aws:iam::001234567890:role/myrole'
enabled = true
storage_allowed_locations = ('*')
storage_blocked_locations = (
's3://mybucket3/path3/', 's3://mybucket4/path4/'
);


alter storage integration gcs_int set
enabled = true
storage_allowed_locations = ('*')
storage_blocked_locations = (
'gcs://mybucket3/path3/', 'gcs://mybucket4/path4/'
);


alter storage integration azure_int set
enabled = true
azure_tenant_id = 'a123b4c5-1234-123a-a12b-1a23b45678c9'
storage_allowed_locations = ('*')
storage_blocked_locations = (
'azure://myaccount.blob.core.windows.net/mycontainer/path3/',
'azure://myaccount.blob.core.windows.net/mycontainer/path4/'
);

alter storage integration azure_int set
enabled = true
comment = 'test_comment'
azure_tenant_id = 'a123b4c5-1234-123a-a12b-1a23b45678c9'
storage_allowed_locations = ('*')
storage_blocked_locations = (
'azure://myaccount.blob.core.windows.net/mycontainer/path3/',
'azure://myaccount.blob.core.windows.net/mycontainer/path4/'
);

alter storage integration if exists azure_int set
enabled = true
comment = 'test_comment'
azure_tenant_id = 'a123b4c5-1234-123a-a12b-1a23b45678c9'
storage_allowed_locations = ('*')
storage_blocked_locations = (
'azure://myaccount.blob.core.windows.net/mycontainer/path3/',
'azure://myaccount.blob.core.windows.net/mycontainer/path4/'
);
Loading

0 comments on commit b0b87c0

Please sign in to comment.