-
Notifications
You must be signed in to change notification settings - Fork 418
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
feat: Add option to create streams which reference EXTERNAL TABLEs #661
Changes from 4 commits
d1b7887
d57e4a0
e279033
d73326f
02267a3
eb335a8
c58be0c
b467077
8377023
a356e27
7b71972
c95a50f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,18 @@ func TestAcc_Stream(t *testing.T) { | |
checkBool("snowflake_stream.test_stream", "show_initial_rows", false), | ||
), | ||
}, | ||
{ | ||
Config: externalTableStreamConfig(accName), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr("snowflake_stream.test_stream", "name", accName), | ||
resource.TestCheckResourceAttr("snowflake_stream.test_stream", "database", accName), | ||
resource.TestCheckResourceAttr("snowflake_stream.test_stream", "schema", accName), | ||
resource.TestCheckResourceAttr("snowflake_stream.test_stream", "on_table", fmt.Sprintf("%s.%s.%s", accName, accName, "STREAM_ON_TABLE")), | ||
resource.TestCheckResourceAttr("snowflake_stream.test_stream", "comment", "Terraform acceptance test"), | ||
checkBool("snowflake_stream.test_stream", "append_only", false), | ||
checkBool("snowflake_stream.test_stream", "show_initial_rows", false), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
@@ -90,3 +102,67 @@ resource "snowflake_stream" "test_stream" { | |
` | ||
return fmt.Sprintf(s, name, name, name, append_only_config) | ||
} | ||
|
||
func externalTableStreamConfig(name string) string { | ||
// Refer to external_table_acceptance_test.go for the original source on | ||
// external table resources and dependents (modified slightly here). | ||
locations := []string{"s3://com.example.bucket/prefix"} | ||
s := ` | ||
resource "snowflake_database" "test" { | ||
name = "%v" | ||
comment = "Terraform acceptance test" | ||
} | ||
|
||
resource "snowflake_schema" "test" { | ||
name = "%v" | ||
database = snowflake_database.test.name | ||
comment = "Terraform acceptance test" | ||
} | ||
|
||
resource "snowflake_stage" "test" { | ||
name = "%v" | ||
url = "s3://com.example.bucket/prefix" | ||
database = snowflake_database.test.name | ||
schema = snowflake_schema.test.name | ||
comment = "Terraform acceptance test" | ||
storage_integration = snowflake_storage_integration.external_table_stream_integration.name | ||
} | ||
|
||
resource "snowflake_storage_integration" "external_table_stream_integration" { | ||
name = "%v" | ||
storage_allowed_locations = %q | ||
storage_provider = "S3" | ||
storage_aws_role_arn = "arn:aws:iam::000000000001:/role/test" | ||
} | ||
|
||
resource "snowflake_external_table" "test_external_stream_table" { | ||
database = snowflake_database.test.name | ||
schema = snowflake_schema.test.name | ||
name = "%v" | ||
comment = "Terraform acceptance test" | ||
column { | ||
name = "column1" | ||
type = "STRING" | ||
as = "TO_VARCHAR(TO_TIMESTAMP_NTZ(value:unix_timestamp_property::NUMBER, 3), 'yyyy-mm-dd-hh')" | ||
} | ||
column { | ||
name = "column2" | ||
type = "TIMESTAMP_NTZ(9)" | ||
as = "($1:'CreatedDate'::timestamp)" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like it's not happy with this... Is this written correctly? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, should be; I grabbed it directly from the |
||
} | ||
file_format = "TYPE = CSV" | ||
location = "@${snowflake_database.test.name}.${snowflake_schema.test.name}.${snowflake_stage.test.name}" | ||
} | ||
|
||
resource "snowflake_stream" "test_external_table_stream" { | ||
database = snowflake_database.test_database.name | ||
momer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
schema = snowflake_schema.test_schema.name | ||
momer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
name = "%s" | ||
comment = "Terraform acceptance test" | ||
on_external_table = true | ||
on_table = "${snowflake_database.test_database.name}.${snowflake_schema.test_schema.name}.${snowflake_external_table.test_external_stream_table.name}" | ||
momer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
` | ||
|
||
return fmt.Sprintf(s, name, name, name, name, locations, name, name) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this supposed to be
on_external_table
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And I think the name is supposed be
accName
, as well... notSTREAM_ON_TABLE
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @alldoami
on_external_table
is abool
, and creating a stream on an external table without... EXTERNAL TABLE
will raise an error; so, the acceptance test is simply ensuring that the table referenced byon_table
(which is an external table created viaexternalTableStreamConfig
) exists.That said, I should definitely have added a check that
on_external_table
istrue
- see the most recent commits, which also resolve theSTREAM_ON_TABLE
reference - thanks! I'll have to set up an environment to run these tests locally which will reduce impact on you via these PRs, sorry.