Skip to content

Commit

Permalink
fix: Allow creation of stage with storage integration including speci…
Browse files Browse the repository at this point in the history
…al characters (#1081)

To support storage integration names including special characters, this
change adds quotes to the names, to avoid generating invalid SQL (e.g.
when names have dashes).

Fixes #1080

Co-authored-by: Jason Lin <[email protected]>
  • Loading branch information
adamantike and sfc-gh-jalin authored Jul 1, 2022
1 parent a3e6e17 commit 7b5bf00
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions pkg/snowflake/stage.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func (sb *StageBuilder) Create() string {
}

if sb.storageIntegration != "" {
q.WriteString(fmt.Sprintf(` STORAGE_INTEGRATION = %v`, sb.storageIntegration))
q.WriteString(fmt.Sprintf(` STORAGE_INTEGRATION = "%v"`, sb.storageIntegration))
}

if sb.encryption != "" {
Expand Down Expand Up @@ -195,7 +195,7 @@ func (sb *StageBuilder) ChangeCredentials(c string) string {

// ChangeStorageIntegration returns the SQL query that will update the storage integration on the stage.
func (sb *StageBuilder) ChangeStorageIntegration(s string) string {
return fmt.Sprintf(`ALTER STAGE %v SET STORAGE_INTEGRATION = %v`, sb.QualifiedName(), s)
return fmt.Sprintf(`ALTER STAGE %v SET STORAGE_INTEGRATION = "%v"`, sb.QualifiedName(), s)
}

// ChangeEncryption returns the SQL query that will update the encryption on the stage.
Expand Down
4 changes: 2 additions & 2 deletions pkg/snowflake/stage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestStageCreate(t *testing.T) {
r.Equal(`CREATE STAGE "test_db"."test_schema"."test_stage" URL = 's3://load/encrypted_files/' CREDENTIALS = (aws_role='arn:aws:iam::001234567890:role/mysnowflakerole') ENCRYPTION = (type='AWS_SSE_KMS' kms_key_id = 'aws/key') FILE_FORMAT = (format_name=my_csv_format) COPY_OPTIONS = (on_error='skip_file') DIRECTORY = (ENABLE=TRUE) COMMENT = 'Yee\'haw'`, s.Create())

s.WithStorageIntegration("MY_INTEGRATION")
r.Equal(`CREATE STAGE "test_db"."test_schema"."test_stage" URL = 's3://load/encrypted_files/' CREDENTIALS = (aws_role='arn:aws:iam::001234567890:role/mysnowflakerole') STORAGE_INTEGRATION = MY_INTEGRATION ENCRYPTION = (type='AWS_SSE_KMS' kms_key_id = 'aws/key') FILE_FORMAT = (format_name=my_csv_format) COPY_OPTIONS = (on_error='skip_file') DIRECTORY = (ENABLE=TRUE) COMMENT = 'Yee\'haw'`, s.Create())
r.Equal(`CREATE STAGE "test_db"."test_schema"."test_stage" URL = 's3://load/encrypted_files/' CREDENTIALS = (aws_role='arn:aws:iam::001234567890:role/mysnowflakerole') STORAGE_INTEGRATION = "MY_INTEGRATION" ENCRYPTION = (type='AWS_SSE_KMS' kms_key_id = 'aws/key') FILE_FORMAT = (format_name=my_csv_format) COPY_OPTIONS = (on_error='skip_file') DIRECTORY = (ENABLE=TRUE) COMMENT = 'Yee\'haw'`, s.Create())
}

func TestStageRename(t *testing.T) {
Expand Down Expand Up @@ -83,7 +83,7 @@ func TestStageChangeCredentials(t *testing.T) {
func TestStageChangeStorageIntegration(t *testing.T) {
r := require.New(t)
s := Stage("test_stage", "test_db", "test_schema")
r.Equal(s.ChangeStorageIntegration("MY_INTEGRATION"), `ALTER STAGE "test_db"."test_schema"."test_stage" SET STORAGE_INTEGRATION = MY_INTEGRATION`)
r.Equal(s.ChangeStorageIntegration("MY_INTEGRATION"), `ALTER STAGE "test_db"."test_schema"."test_stage" SET STORAGE_INTEGRATION = "MY_INTEGRATION"`)
}

func TestStageChangeCopyOptions(t *testing.T) {
Expand Down

0 comments on commit 7b5bf00

Please sign in to comment.