diff --git a/catalog/resource_sql_table.go b/catalog/resource_sql_table.go index 66d692ee94..49ebcc1427 100644 --- a/catalog/resource_sql_table.go +++ b/catalog/resource_sql_table.go @@ -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") } } diff --git a/catalog/resource_sql_table_test.go b/catalog/resource_sql_table_test.go index f2742f7def..f2505d00d6 100644 --- a/catalog/resource_sql_table_test.go +++ b/catalog/resource_sql_table_test.go @@ -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 { @@ -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 } @@ -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 {