Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
edwardfeng-db committed Mar 11, 2024
1 parent f0c3b96 commit 4e4dbee
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 6 deletions.
4 changes: 0 additions & 4 deletions catalog/resource_sql_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -436,15 +436,11 @@ func ResourceSqlTable() common.Resource {

// Only handling same number of columns for now, will address different number of columns as a follow-up.
if len(oldCols) == len(newCols) {
println("same length")
for i, oldCol := range oldCols {
oldColMap := oldCol.(map[string]interface{})
newColMap := newCols[i].(map[string]interface{})
println(oldColMap["type"])
println(newColMap["type"])

if oldColMap["type"] != newColMap["type"] {
println("type diff!")
return fmt.Errorf("changing the 'type' of an existing column is not allowed, please apply twice by dropping and adding a new column")
}
}
Expand Down
77 changes: 75 additions & 2 deletions catalog/resource_sql_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ func TestResourceSqlTableUpdateView_Comments(t *testing.T) {
func TestResourceSqlTableUpdateTable_Columns(t *testing.T) {
allowedCommands := []string{
"ALTER TABLE `main`.`foo`.`bar` ALTER COLUMN `one` COMMENT managed comment",
"ALTER TABLE `main`.`foo`.`bar` RENAME COLUMN `two` to `three",
"ALTER TABLE `main`.`foo`.`bar` RENAME COLUMN `two` to `three`",
}
d, err := qa.ResourceFixture{
CommandMock: func(commandStr string) common.CommandResults {
Expand All @@ -612,7 +612,7 @@ func TestResourceSqlTableUpdateTable_Columns(t *testing.T) {
cluster_id = "gone"
column {
name = "one"
type = "int"
type = "string"
comment = "managed comment"
nullable = false
}
Expand Down Expand Up @@ -685,6 +685,79 @@ func TestResourceSqlTableUpdateTable_Columns(t *testing.T) {
assert.Equal(t, "bar", d.Get("name"))
}

func TestResourceSqlTableUpdateTable_ColumnsTypeThrowsError(t *testing.T) {
_, err := qa.ResourceFixture{
HCL: `
name = "bar"
catalog_name = "main"
schema_name = "foo"
table_type = "EXTERNAL"
data_source_format = "DELTA"
storage_location = "s3://ext-main/foo/bar1"
comment = "terraform managed"
cluster_id = "gone"
column {
name = "one"
type = "int"
comment = "managed comment"
nullable = false
}
`,
InstanceState: map[string]string{
"name": "bar",
"catalog_name": "main",
"schema_name": "foo",
"table_type": "EXTERNAL",
"data_source_format": "DELTA",
"storage_location": "s3://ext-main/foo/bar1",
"comment": "terraform managed",
"column.#": "2",
"column.0.name": "one",
"column.0.type": "string",
"column.0.comment": "old comment",
"column.0.nullable": "false",
},
Fixtures: append([]qa.HTTPFixture{
{
Method: "GET",
Resource: "/api/2.1/unity-catalog/tables/main.foo.bar",
ReuseRequest: true,
Response: SqlTableInfo{
Name: "bar",
CatalogName: "main",
SchemaName: "foo",
TableType: "EXTERNAL",
DataSourceFormat: "DELTA",
StorageLocation: "s3://ext-main/foo/bar1",
StorageCredentialName: "somecred",
Comment: "terraform managed",
ColumnInfos: []SqlColumnInfo{
{
Name: "one",
Type: "string",
Comment: "old comment",
Nullable: false,
},
},
},
},
{
Method: "POST",
Resource: "/api/2.0/clusters/start",
ExpectedRequest: clusters.ClusterID{
ClusterID: "gone",
},
Status: 404,
},
}, createClusterForSql...),
Resource: ResourceSqlTable(),
ID: "main.foo.bar",
Update: true,
}.Apply(t)

assert.EqualError(t, err, "changing the 'type' of an existing column is not allowed, please apply twice by dropping and adding a new column")
}

func TestResourceSqlTableCreateTable_ExistingSQLWarehouse(t *testing.T) {
_, err := qa.ResourceFixture{
CommandMock: func(commandStr string) common.CommandResults {
Expand Down

0 comments on commit 4e4dbee

Please sign in to comment.