Skip to content

Commit

Permalink
fix - stage format name
Browse files Browse the repository at this point in the history
  • Loading branch information
mlorek committed Aug 14, 2023
1 parent 79d9c9c commit 81564db
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
18 changes: 14 additions & 4 deletions pkg/resources/stage_acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ 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/"),
),
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/"),
Expand All @@ -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"
Expand All @@ -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)
}
4 changes: 2 additions & 2 deletions pkg/snowflake/stage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 != "" {
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 81564db

Please sign in to comment.