From 81564db9bbe8564423959fe20c805852112dd8a8 Mon Sep 17 00:00:00 2001 From: mlorek Date: Mon, 14 Aug 2023 10:01:27 +0100 Subject: [PATCH] fix - stage format name --- pkg/resources/stage_acceptance_test.go | 18 ++++++++++++++---- pkg/snowflake/stage.go | 4 ++-- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/pkg/resources/stage_acceptance_test.go b/pkg/resources/stage_acceptance_test.go index 820fa45480..fb6c8b7abc 100644 --- a/pkg/resources/stage_acceptance_test.go +++ b/pkg/resources/stage_acceptance_test.go @@ -16,7 +16,7 @@ func TestAccAlterStageWhenBothURLAndStorageIntegrationChange(t *testing.T) { CheckDestroy: nil, Steps: []resource.TestStep{ { - Config: stageIntegrationConfig(name, "si1", "s3://foo/"), + Config: stageIntegrationConfig(name, "si1", "s3://foo/", "ff1"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("snowflake_stage.test", "name", name), resource.TestCheckResourceAttr("snowflake_stage.test", "url", "s3://foo/"), @@ -24,7 +24,7 @@ func TestAccAlterStageWhenBothURLAndStorageIntegrationChange(t *testing.T) { Destroy: false, }, { - Config: stageIntegrationConfig(name, "changed", "s3://changed/"), + Config: stageIntegrationConfig(name, "changed", "s3://changed/", "ff2"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("snowflake_stage.test", "name", name), resource.TestCheckResourceAttr("snowflake_stage.test", "url", "s3://changed/"), @@ -34,7 +34,7 @@ func TestAccAlterStageWhenBothURLAndStorageIntegrationChange(t *testing.T) { }) } -func stageIntegrationConfig(name string, siNameSuffix string, url string) string { +func stageIntegrationConfig(name string, siNameSuffix string, url string, ffName string) string { resources := ` resource "snowflake_database" "test" { name = "%s" @@ -61,8 +61,18 @@ resource "snowflake_stage" "test" { storage_integration = snowflake_storage_integration.test.name schema = snowflake_schema.test.name database = snowflake_database.test.name + file_format = snowflake_file_format.test.name +} + +resource "snowflake_file_format" "test" { + database = snowflake_database.test.name + schema = snowflake_schema.test.name + name = "%s" + format_type = "JSON" + compression = "GZIP" + skip_byte_order_mark = true } ` - return fmt.Sprintf(resources, name, name, name, siNameSuffix, url, name, url) + return fmt.Sprintf(resources, name, name, name, siNameSuffix, url, name, url, ffName) } diff --git a/pkg/snowflake/stage.go b/pkg/snowflake/stage.go index b96c1df016..b1a7a68845 100644 --- a/pkg/snowflake/stage.go +++ b/pkg/snowflake/stage.go @@ -150,7 +150,7 @@ func (sb *StageBuilder) Create() string { } if sb.fileFormat != "" { - q.WriteString(fmt.Sprintf(` FILE_FORMAT = (%v)`, fixFileFormat(sb.fileFormat))) + q.WriteString(fmt.Sprintf(` FILE_FORMAT = %v`, fixFileFormat(sb.fileFormat))) } if sb.copyOptions != "" { @@ -209,7 +209,7 @@ func (sb *StageBuilder) ChangeEncryption(e string) string { // ChangeFileFormat returns the SQL query that will update the file format on the stage. func (sb *StageBuilder) ChangeFileFormat(f string) string { - return fmt.Sprintf(`ALTER STAGE %v SET FILE_FORMAT = (%v)`, sb.QualifiedName(), fixFileFormat(f)) + return fmt.Sprintf(`ALTER STAGE %v SET FILE_FORMAT = %v`, sb.QualifiedName(), fixFileFormat(f)) } // ChangeCopyOptions returns the SQL query that will update the copy options on the stage.