Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: stage format name #2010

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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