Skip to content

Commit

Permalink
feat: add the param "pattern" for snowflake_external_table (#657)
Browse files Browse the repository at this point in the history
  • Loading branch information
hkak03key committed Aug 24, 2021
1 parent c906e01 commit 4b5aef6
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
1 change: 1 addition & 0 deletions docs/resources/external_table.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ resource snowflake_external_table external_table {
- **copy_grants** (Boolean) Specifies to retain the access permissions from the original table when an external table is recreated using the CREATE OR REPLACE TABLE variant
- **id** (String) The ID of this resource.
- **partition_by** (List of String) Specifies any partition columns to evaluate for the external table.
- **pattern** (String) Specifies the file names and/or paths on the external stage to match.
- **refresh_on_create** (Boolean) Specifies weather to refresh when an external table is created.

### Read-Only
Expand Down
7 changes: 6 additions & 1 deletion pkg/resources/external_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,12 @@ var externalTableSchema = map[string]*schema.Schema{
ForceNew: true,
Description: "Specifies the file format for the external table.",
},

"pattern": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Description: "Specifies the file names and/or paths on the external stage to match.",
},
"aws_sns_topic": {
Type: schema.TypeString,
Optional: true,
Expand Down
3 changes: 2 additions & 1 deletion pkg/resources/external_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ func TestExternalTableCreate(t *testing.T) {
"column": []interface{}{map[string]interface{}{"name": "column1", "type": "OBJECT", "as": "a"}, map[string]interface{}{"name": "column2", "type": "VARCHAR", "as": "b"}},
"location": "location",
"file_format": "format",
"pattern": "pattern",
}
d := externalTable(t, "database_name|schema_name|good_name", in)

WithMockDb(t, func(db *sql.DB, mock sqlmock.Sqlmock) {
mock.ExpectExec(`CREATE EXTERNAL TABLE "database_name"."schema_name"."good_name" \("column1" OBJECT AS a, "column2" VARCHAR AS b\) WITH LOCATION = location REFRESH_ON_CREATE = true AUTO_REFRESH = true FILE_FORMAT = \( format \) COMMENT = 'great comment'`).WillReturnResult(sqlmock.NewResult(1, 1))
mock.ExpectExec(`CREATE EXTERNAL TABLE "database_name"."schema_name"."good_name" \("column1" OBJECT AS a, "column2" VARCHAR AS b\) WITH LOCATION = location REFRESH_ON_CREATE = true AUTO_REFRESH = true PATTERN = 'pattern' FILE_FORMAT = \( format \) COMMENT = 'great comment'`).WillReturnResult(sqlmock.NewResult(1, 1))

expectExternalTableRead(mock)
err := resources.CreateExternalTable(d, db)
Expand Down
5 changes: 3 additions & 2 deletions pkg/snowflake/external_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ func TestExternalTableCreate(t *testing.T) {
s := ExternalTable("test_table", "test_db", "test_schema")
s.WithColumns([]map[string]string{{"name": "column1", "type": "OBJECT", "as": "expression1"}, {"name": "column2", "type": "VARCHAR", "as": "expression2"}})
s.WithLocation("location")
s.WithPattern("pattern")
s.WithFileFormat("file format")
r.Equal(s.QualifiedName(), `"test_db"."test_schema"."test_table"`)

r.Equal(s.Create(), `CREATE EXTERNAL TABLE "test_db"."test_schema"."test_table" ("column1" OBJECT AS expression1, "column2" VARCHAR AS expression2) WITH LOCATION = location REFRESH_ON_CREATE = false AUTO_REFRESH = false FILE_FORMAT = ( file format )`)
r.Equal(s.Create(), `CREATE EXTERNAL TABLE "test_db"."test_schema"."test_table" ("column1" OBJECT AS expression1, "column2" VARCHAR AS expression2) WITH LOCATION = location REFRESH_ON_CREATE = false AUTO_REFRESH = false PATTERN = 'pattern' FILE_FORMAT = ( file format )`)

s.WithComment("Test Comment")
r.Equal(s.Create(), `CREATE EXTERNAL TABLE "test_db"."test_schema"."test_table" ("column1" OBJECT AS expression1, "column2" VARCHAR AS expression2) WITH LOCATION = location REFRESH_ON_CREATE = false AUTO_REFRESH = false FILE_FORMAT = ( file format ) COMMENT = 'Test Comment'`)
r.Equal(s.Create(), `CREATE EXTERNAL TABLE "test_db"."test_schema"."test_table" ("column1" OBJECT AS expression1, "column2" VARCHAR AS expression2) WITH LOCATION = location REFRESH_ON_CREATE = false AUTO_REFRESH = false PATTERN = 'pattern' FILE_FORMAT = ( file format ) COMMENT = 'Test Comment'`)
}

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

0 comments on commit 4b5aef6

Please sign in to comment.