From bc8252edb698d46b248e3e872de617efe5213bd1 Mon Sep 17 00:00:00 2001 From: Vuong Date: Wed, 12 Feb 2025 09:35:42 +0700 Subject: [PATCH 1/5] limitations of importing `databricks_sql_table` --- docs/resources/sql_table.md | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/docs/resources/sql_table.md b/docs/resources/sql_table.md index 27d57aa11..34d8ffa3d 100644 --- a/docs/resources/sql_table.md +++ b/docs/resources/sql_table.md @@ -9,7 +9,7 @@ A `databricks_sql_table` is contained within [databricks_schema](schema.md), and This resource creates and updates the Unity Catalog table/view by executing the necessary SQL queries on a special auto-terminating cluster it would create for this operation. You could also specify a SQL warehouse or cluster for the queries to be executed on. -~> This resource doesn't handle complex cases of schema evolution due to the limitations of Terraform itself. If you need to implement schema evolution it's recommended to use specialized tools, such as, [Luquibase](https://medium.com/dbsql-sme-engineering/advanced-schema-management-on-databricks-with-liquibase-1900e9f7b9c0) and [Flyway](https://medium.com/dbsql-sme-engineering/databricks-schema-management-with-flyway-527c4a9f5d67). +~> This resource doesn't handle complex cases of schema evolution due to the limitations of Terraform itself. If you need to implement schema evolution it's recommended to use specialized tools, such as, [Liquibase](https://medium.com/dbsql-sme-engineering/advanced-schema-management-on-databricks-with-liquibase-1900e9f7b9c0) and [Flyway](https://medium.com/dbsql-sme-engineering/databricks-schema-management-with-flyway-527c4a9f5d67). ## Example Usage @@ -162,15 +162,15 @@ The following arguments are supported: * `storage_location` - (Optional) URL of storage location for Table data (required for EXTERNAL Tables). Not supported for `VIEW` or `MANAGED` table_type. * `data_source_format` - (Optional) External tables are supported in multiple data source formats. The string constants identifying these formats are `DELTA`, `CSV`, `JSON`, `AVRO`, `PARQUET`, `ORC`, and `TEXT`. Change forces the creation of a new resource. Not supported for `MANAGED` tables or `VIEW`. * `view_definition` - (Optional) SQL text defining the view (for `table_type == "VIEW"`). Not supported for `MANAGED` or `EXTERNAL` table_type. -* `cluster_id` - (Optional) All table CRUD operations must be executed on a running cluster or SQL warehouse. If a cluster_id is specified, it will be used to execute SQL commands to manage this table. If empty, a cluster will be created automatically with the name `terraform-sql-table`. +* `cluster_id` - (Optional) All table CRUD operations must be executed on a running cluster or SQL warehouse. If a cluster_id is specified, it will be used to execute SQL commands to manage this table. If empty, a cluster will be created automatically with the name `terraform-sql-table`. Conflicts with `warehouse_id`. * `warehouse_id` - (Optional) All table CRUD operations must be executed on a running cluster or SQL warehouse. If a `warehouse_id` is specified, that SQL warehouse will be used to execute SQL commands to manage this table. Conflicts with `cluster_id`. * `cluster_keys` - (Optional) a subset of columns to liquid cluster the table by. Conflicts with `partitions`. +* `partitions` - (Optional) a subset of columns to partition the table by. Change forces the creation of a new resource. Conflicts with `cluster_keys`. * `storage_credential_name` - (Optional) For EXTERNAL Tables only: the name of storage credential to use. Change forces the creation of a new resource. -* `owner` - (Optional) User name/group name/sp application_id of the schema owner. +* `owner` - (Optional) User name/group name/sp application_id of the table owner. * `comment` - (Optional) User-supplied free-form text. Changing the comment is not currently supported on the `VIEW` table type. * `options` - (Optional) Map of user defined table options. Change forces creation of a new resource. * `properties` - (Optional) A map of table properties. -* `partitions` - (Optional) a subset of columns to partition the table by. Change forces the creation of a new resource. Conflicts with `cluster_keys`. Change forces creation of a new resource. ### `column` configuration block @@ -191,7 +191,7 @@ In addition to all the arguments above, the following attributes are exported: ## Import -This resource can be imported by its full name: +This resource can be imported by its full name. `partitions` attribute is not imported due to Unity Catalog limitations and therefore should not be specified: ```bash terraform import databricks_sql_table.this .. @@ -200,11 +200,13 @@ terraform import databricks_sql_table.this .. ## Migration from `databricks_table` The `databricks_table` resource has been deprecated in favor of `databricks_sql_table`. To migrate from `databricks_table` to `databricks_sql_table`: + 1. Define a `databricks_sql_table` resource with arguments corresponding to `databricks_table`. 2. Add a `removed` block to remove the `databricks_table` resource without deleting the existing table by using the `lifecycle` block. If you're using Terraform version below v1.7.0, you will need to use the `terraform state rm` command instead. 3. Add an `import` block to add the `databricks_sql_table` resource, corresponding to the existing table. If you're using Terraform version below v1.5.0, you will need to use `terraform import` command instead. For example, suppose we have the following `databricks_table` resource: + ```hcl resource "databricks_table" "this" { catalog_name = "catalog" @@ -227,6 +229,7 @@ resource "databricks_table" "this" { ``` The migration would look like this: + ```hcl # Leave this resource definition as-is. resource "databricks_table" "this" { ... } From a6294339f84a29bc1d26699a94a9b43b147edd55 Mon Sep 17 00:00:00 2001 From: Vuong Date: Wed, 12 Feb 2025 09:40:54 +0700 Subject: [PATCH 2/5] add doc --- NEXT_CHANGELOG.md | 1 + docs/resources/sql_table.md | 14 +++++++------- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/NEXT_CHANGELOG.md b/NEXT_CHANGELOG.md index 343d1b76a..6416eb3df 100644 --- a/NEXT_CHANGELOG.md +++ b/NEXT_CHANGELOG.md @@ -17,6 +17,7 @@ * Add an example for Databricks Apps permissions ([#4475](https://github.com/databricks/terraform-provider-databricks/pull/4475)). * Add explanation of timeouts to the troubleshooting guide ([#4482](https://github.com/databricks/terraform-provider-databricks/pull/4482)). * Clarify that `databricks_token` and `databricks_obo_token` could be used only with workspace-level provider ([#4480](https://github.com/databricks/terraform-provider-databricks/pull/4480)). + * Clarify limitations whe importing `databricks_sql_table` ([#4483](https://github.com/databricks/terraform-provider-databricks/pull/4483)). ### Exporter diff --git a/docs/resources/sql_table.md b/docs/resources/sql_table.md index 34d8ffa3d..1175331b8 100644 --- a/docs/resources/sql_table.md +++ b/docs/resources/sql_table.md @@ -209,17 +209,17 @@ For example, suppose we have the following `databricks_table` resource: ```hcl resource "databricks_table" "this" { - catalog_name = "catalog" - schema_name = "schema" - name = "table" - table_type = "MANAGED" + catalog_name = "catalog" + schema_name = "schema" + name = "table" + table_type = "MANAGED" data_source_format = "DELTA" column { - name = "col1" + name = "col1" type_name = "STRING" type_json = "{\"type\":\"STRING\"}" - comment = "comment" - nullable = true + comment = "comment" + nullable = true } comment = "comment" properties = { From 3c95593fecdffd7dbbd7503b12f72319fcb87204 Mon Sep 17 00:00:00 2001 From: Vuong Date: Thu, 13 Feb 2025 11:45:46 +0800 Subject: [PATCH 3/5] populate `partitions` when reading `databricks_sql_table` --- NEXT_CHANGELOG.md | 3 +- catalog/resource_sql_table.go | 41 +++++++++ catalog/resource_sql_table_test.go | 130 +++++++++++++++++++++++++++++ docs/resources/sql_table.md | 2 +- 4 files changed, 173 insertions(+), 3 deletions(-) diff --git a/NEXT_CHANGELOG.md b/NEXT_CHANGELOG.md index 1f4bdd4c0..075cc3efe 100644 --- a/NEXT_CHANGELOG.md +++ b/NEXT_CHANGELOG.md @@ -8,7 +8,7 @@ ### Bug Fixes * Fixed an issue where reordering objects in a (pluginfw) Share wouldn’t update properly unless other changes were made ([#4481](https://github.com/databricks/terraform-provider-databricks/pull/4481)). - + * Populate `partitions` when reading `databricks_sql_table` ([#4483](https://github.com/databricks/terraform-provider-databricks/pull/4483)). * Suppress `options.pem_private_key_expiration_epoch_sec` attribute for databricks_connection ([#4474](https://github.com/databricks/terraform-provider-databricks/pull/4474)). ### Documentation @@ -16,7 +16,6 @@ * Add an example for Databricks Apps permissions ([#4475](https://github.com/databricks/terraform-provider-databricks/pull/4475)). * Add explanation of timeouts to the troubleshooting guide ([#4482](https://github.com/databricks/terraform-provider-databricks/pull/4482)). * Clarify that `databricks_token` and `databricks_obo_token` could be used only with workspace-level provider ([#4480](https://github.com/databricks/terraform-provider-databricks/pull/4480)). - * Clarify limitations whe importing `databricks_sql_table` ([#4483](https://github.com/databricks/terraform-provider-databricks/pull/4483)). ### Exporter diff --git a/catalog/resource_sql_table.go b/catalog/resource_sql_table.go index 2eafdf801..2d0618e4c 100644 --- a/catalog/resource_sql_table.go +++ b/catalog/resource_sql_table.go @@ -7,6 +7,7 @@ import ( "log" "reflect" "slices" + "sort" "strings" "time" @@ -67,6 +68,16 @@ type SqlTableInfo struct { sqlExec sql.StatementExecutionInterface } +// need a separate struct as partition_index is 0-based +type ColumnPartitionInfo struct { + Name string `json:"name"` + PartitionIndex *int `json:"partition_index,omitempty"` +} + +type PartitionInfo struct { + ColumnInfos []ColumnPartitionInfo `json:"columns,omitempty"` +} + func (ti SqlTableInfo) CustomizeSchema(s *common.CustomizableSchema) *common.CustomizableSchema { caseInsensitiveFields := []string{"name", "catalog_name", "schema_name"} for _, field := range caseInsensitiveFields { @@ -109,6 +120,11 @@ func (a SqlTablesAPI) getTable(name string) (ti SqlTableInfo, err error) { return } +func (a SqlTablesAPI) getPartitions(name string) (ti PartitionInfo, err error) { + err = a.client.Get(a.context, "/unity-catalog/tables/"+name, nil, &ti) + return +} + func (ti *SqlTableInfo) FullName() string { return fmt.Sprintf("%s.%s.%s", ti.CatalogName, ti.SchemaName, ti.Name) } @@ -668,6 +684,11 @@ func ResourceSqlTable() common.Resource { if err != nil { return err } + partitionInfo, err := NewSqlTablesAPI(ctx, c).getPartitions(d.Id()) + if err != nil { + return err + } + partitionIndexes := map[int]string{} for i := range ti.ColumnInfos { c := &ti.ColumnInfos[i] c.Identity, err = reconstructIdentity(c) @@ -675,6 +696,26 @@ func ResourceSqlTable() common.Resource { return err } } + + for i := range partitionInfo.ColumnInfos { + c := &partitionInfo.ColumnInfos[i] + if c.PartitionIndex != nil { + partitionIndexes[*c.PartitionIndex] = c.Name + } + } + indexes := []int{} + partitions := []string{} + + for index := range partitionIndexes { + indexes = append(indexes, index) + } + sort.Ints(indexes) + + for _, p := range indexes { + partitions = append(partitions, partitionIndexes[p]) + } + + d.Set("partitions", partitions) return common.StructToData(ti, tableSchema, d) }, Update: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { diff --git a/catalog/resource_sql_table_test.go b/catalog/resource_sql_table_test.go index b2495480c..2cec4abae 100644 --- a/catalog/resource_sql_table_test.go +++ b/catalog/resource_sql_table_test.go @@ -229,6 +229,11 @@ func TestResourceSqlTableCreateTable(t *testing.T) { }, }, }, + { + Method: "GET", + Resource: "/api/2.1/unity-catalog/tables/main.foo.bar", + Response: PartitionInfo{}, + }, }, useExistingClusterForSql...), Create: true, Resource: ResourceSqlTable(), @@ -304,6 +309,11 @@ func TestResourceSqlTableCreateTableWithOwner(t *testing.T) { }, }, }, + { + Method: "GET", + Resource: "/api/2.1/unity-catalog/tables/main.foo.bar", + Response: PartitionInfo{}, + }, }, useExistingClusterForSql...), Create: true, Resource: ResourceSqlTable(), @@ -822,6 +832,11 @@ func TestResourceSqlTableUpdateView_Definition(t *testing.T) { ViewDefinition: "SELECT * FROM main.foo.bar2", }, }, + { + Method: "GET", + Resource: "/api/2.1/unity-catalog/tables/main.foo.barview", + Response: PartitionInfo{}, + }, { Method: "POST", Resource: "/api/2.0/clusters/start", @@ -877,6 +892,11 @@ func TestResourceSqlTableUpdateView_Comments(t *testing.T) { Comment: "to be changed (requires new)", }, }, + { + Method: "GET", + Resource: "/api/2.1/unity-catalog/tables/main.foo.barview", + Response: PartitionInfo{}, + }, { Method: "POST", Resource: "/api/2.0/clusters/start", @@ -1357,6 +1377,11 @@ func TestResourceSqlTableCreateTable_ExistingSQLWarehouse(t *testing.T) { }, }, }, + { + Method: "GET", + Resource: "/api/2.1/unity-catalog/tables/main.foo.bar", + Response: PartitionInfo{}, + }, }, Create: true, Resource: ResourceSqlTable(), @@ -1450,6 +1475,11 @@ func TestResourceSqlTableCreateTableWithIdentityColumn_ExistingSQLWarehouse(t *t }, }, }, + { + Method: "GET", + Resource: "/api/2.1/unity-catalog/tables/main.foo.bar", + Response: PartitionInfo{}, + }, }, Create: true, Resource: ResourceSqlTable(), @@ -1516,6 +1546,11 @@ func TestResourceSqlTableReadTableWithIdentityColumn_ExistingSQLWarehouse(t *tes }, }, }, + { + Method: "GET", + Resource: "/api/2.1/unity-catalog/tables/main.foo.bar", + Response: PartitionInfo{}, + }, }, ID: "main.foo.bar", Read: true, @@ -1527,6 +1562,96 @@ func TestResourceSqlTableReadTableWithIdentityColumn_ExistingSQLWarehouse(t *tes }) } +func getPtr(num int) *int { + return &num +} +func TestResourceSqlTableReadTableWithPartitionColumn_ExistingSQLWarehouse(t *testing.T) { + qa.ResourceFixture{ + CommandMock: func(commandStr string) common.CommandResults { + return common.CommandResults{ + ResultType: "", + Data: nil, + } + }, + HCL: ` + name = "bar" + catalog_name = "main" + schema_name = "foo" + table_type = "MANAGED" + data_source_format = "DELTA" + storage_location = "abfss://container@account/somepath" + warehouse_id = "existingwarehouse" + + + comment = "this table is managed by terraform" + `, + Fixtures: []qa.HTTPFixture{ + { + Method: "GET", + Resource: "/api/2.1/unity-catalog/tables/main.foo.bar", + Response: SqlTableInfo{ + Name: "bar", + CatalogName: "main", + SchemaName: "foo", + TableType: "EXTERNAL", + DataSourceFormat: "DELTA", + StorageLocation: "s3://ext-main/foo/bar1", + StorageCredentialName: "somecred", + Comment: "terraform managed", + Properties: map[string]string{ + "one": "two", + "three": "four", + }, + ColumnInfos: []SqlColumnInfo{ + { + Name: "id", + Type: "bigint", + TypeJson: "{\"type\":\"bigint\",\"nullable\":true, \"metadata\":{\"delta.identity.start\":1,\"delta.identity.allowExplicitInsert\":false}}", + }, + { + Name: "name", + Type: "string", + Comment: "name of thing", + }, + { + Name: "number", + Type: "bigint", + TypeJson: "{\"type\":\"bigint\",\"nullable\":true, \"metadata\":{\"delta.identity.start\":1,\"delta.identity.allowExplicitInsert\":true}}", + }, + }, + }, + }, + { + Method: "GET", + Resource: "/api/2.1/unity-catalog/tables/main.foo.bar", + Response: PartitionInfo{ + ColumnInfos: []ColumnPartitionInfo{ + { + Name: "id", + PartitionIndex: getPtr(1), + }, + { + Name: "name", + PartitionIndex: getPtr(0), + }, + { + Name: "number", + }, + }, + }, + }, + }, + ID: "main.foo.bar", + Read: true, + Resource: ResourceSqlTable(), + }.ApplyAndExpectData(t, map[string]any{ + "column.0.identity": "always", + "column.1.identity": "", + "column.2.identity": "default", + "partitions": []any{"name", "id"}, + }) +} + func TestResourceSqlTableCreateTable_OnlyManagedProperties(t *testing.T) { qa.ResourceFixture{ CommandMock: func(commandStr string) common.CommandResults { @@ -1587,6 +1712,11 @@ func TestResourceSqlTableCreateTable_OnlyManagedProperties(t *testing.T) { }, }, }, + { + Method: "GET", + Resource: "/api/2.1/unity-catalog/tables/main.foo.bar", + Response: PartitionInfo{}, + }, }, Create: true, Resource: ResourceSqlTable(), diff --git a/docs/resources/sql_table.md b/docs/resources/sql_table.md index 1175331b8..802288ba2 100644 --- a/docs/resources/sql_table.md +++ b/docs/resources/sql_table.md @@ -191,7 +191,7 @@ In addition to all the arguments above, the following attributes are exported: ## Import -This resource can be imported by its full name. `partitions` attribute is not imported due to Unity Catalog limitations and therefore should not be specified: +This resource can be imported by its full name. ```bash terraform import databricks_sql_table.this .. From 973220de1ad95ede2674943f5e439832f877ac33 Mon Sep 17 00:00:00 2001 From: Vuong Date: Fri, 21 Feb 2025 16:06:22 +0800 Subject: [PATCH 4/5] feedback --- catalog/resource_sql_table.go | 29 ++++-------- catalog/resource_sql_table_test.go | 76 ++++++++++++++++++++---------- 2 files changed, 59 insertions(+), 46 deletions(-) diff --git a/catalog/resource_sql_table.go b/catalog/resource_sql_table.go index 2d0618e4c..d000b8a70 100644 --- a/catalog/resource_sql_table.go +++ b/catalog/resource_sql_table.go @@ -68,16 +68,6 @@ type SqlTableInfo struct { sqlExec sql.StatementExecutionInterface } -// need a separate struct as partition_index is 0-based -type ColumnPartitionInfo struct { - Name string `json:"name"` - PartitionIndex *int `json:"partition_index,omitempty"` -} - -type PartitionInfo struct { - ColumnInfos []ColumnPartitionInfo `json:"columns,omitempty"` -} - func (ti SqlTableInfo) CustomizeSchema(s *common.CustomizableSchema) *common.CustomizableSchema { caseInsensitiveFields := []string{"name", "catalog_name", "schema_name"} for _, field := range caseInsensitiveFields { @@ -120,11 +110,6 @@ func (a SqlTablesAPI) getTable(name string) (ti SqlTableInfo, err error) { return } -func (a SqlTablesAPI) getPartitions(name string) (ti PartitionInfo, err error) { - err = a.client.Get(a.context, "/unity-catalog/tables/"+name, nil, &ti) - return -} - func (ti *SqlTableInfo) FullName() string { return fmt.Sprintf("%s.%s.%s", ti.CatalogName, ti.SchemaName, ti.Name) } @@ -684,7 +669,11 @@ func ResourceSqlTable() common.Resource { if err != nil { return err } - partitionInfo, err := NewSqlTablesAPI(ctx, c).getPartitions(d.Id()) + w, err := c.WorkspaceClient() + if err != nil { + return err + } + partitionInfo, err := w.Tables.GetByFullName(ctx, d.Id()) if err != nil { return err } @@ -697,10 +686,10 @@ func ResourceSqlTable() common.Resource { } } - for i := range partitionInfo.ColumnInfos { - c := &partitionInfo.ColumnInfos[i] - if c.PartitionIndex != nil { - partitionIndexes[*c.PartitionIndex] = c.Name + for i := range partitionInfo.Columns { + c := &partitionInfo.Columns[i] + if slices.Contains(c.ForceSendFields, "PartitionIndex") { + partitionIndexes[c.PartitionIndex] = c.Name } } indexes := []int{} diff --git a/catalog/resource_sql_table_test.go b/catalog/resource_sql_table_test.go index 2cec4abae..c4fb9ab07 100644 --- a/catalog/resource_sql_table_test.go +++ b/catalog/resource_sql_table_test.go @@ -231,8 +231,8 @@ func TestResourceSqlTableCreateTable(t *testing.T) { }, { Method: "GET", - Resource: "/api/2.1/unity-catalog/tables/main.foo.bar", - Response: PartitionInfo{}, + Resource: "/api/2.1/unity-catalog/tables/main.foo.bar?", + Response: catalog.TableInfo{}, }, }, useExistingClusterForSql...), Create: true, @@ -311,8 +311,8 @@ func TestResourceSqlTableCreateTableWithOwner(t *testing.T) { }, { Method: "GET", - Resource: "/api/2.1/unity-catalog/tables/main.foo.bar", - Response: PartitionInfo{}, + Resource: "/api/2.1/unity-catalog/tables/main.foo.bar?", + Response: catalog.TableInfo{}, }, }, useExistingClusterForSql...), Create: true, @@ -436,6 +436,11 @@ func TestResourceSqlTableUpdateTable(t *testing.T) { }, }, }, + { + Method: "GET", + Resource: "/api/2.1/unity-catalog/tables/main.foo.bar?", + Response: catalog.TableInfo{}, + }, { Method: "POST", Resource: "/api/2.0/clusters/start", @@ -537,6 +542,11 @@ func TestResourceSqlTableUpdateTableAndOwner(t *testing.T) { Owner: "old group", }, }, + { + Method: "GET", + Resource: "/api/2.1/unity-catalog/tables/main.foo.bar?", + Response: catalog.TableInfo{}, + }, { Method: "POST", Resource: "/api/2.0/clusters/start", @@ -633,6 +643,11 @@ func TestResourceSqlTableUpdateTableClusterKeys(t *testing.T) { }, }, }, + { + Method: "GET", + Resource: "/api/2.1/unity-catalog/tables/main.foo.bar?", + Response: catalog.TableInfo{}, + }, { Method: "POST", Resource: "/api/2.0/clusters/start", @@ -723,6 +738,11 @@ func TestResourceSqlTableUpdateView(t *testing.T) { }, }, }, + { + Method: "GET", + Resource: "/api/2.1/unity-catalog/tables/main.foo.bar?", + Response: catalog.TableInfo{}, + }, { Method: "POST", Resource: "/api/2.0/clusters/start", @@ -834,8 +854,8 @@ func TestResourceSqlTableUpdateView_Definition(t *testing.T) { }, { Method: "GET", - Resource: "/api/2.1/unity-catalog/tables/main.foo.barview", - Response: PartitionInfo{}, + Resource: "/api/2.1/unity-catalog/tables/main.foo.barview?", + Response: catalog.TableInfo{}, }, { Method: "POST", @@ -894,8 +914,8 @@ func TestResourceSqlTableUpdateView_Comments(t *testing.T) { }, { Method: "GET", - Resource: "/api/2.1/unity-catalog/tables/main.foo.barview", - Response: PartitionInfo{}, + Resource: "/api/2.1/unity-catalog/tables/main.foo.barview?", + Response: catalog.TableInfo{}, }, { Method: "POST", @@ -989,6 +1009,11 @@ func resourceSqlTableUpdateColumnHelper(t *testing.T, testMetaData resourceSqlTa ColumnInfos: testMetaData.oldColumns, }, }, + { + Method: "GET", + Resource: "/api/2.1/unity-catalog/tables/main.foo.bar?", + Response: catalog.TableInfo{}, + }, { Method: "POST", Resource: "/api/2.0/clusters/start", @@ -1379,8 +1404,8 @@ func TestResourceSqlTableCreateTable_ExistingSQLWarehouse(t *testing.T) { }, { Method: "GET", - Resource: "/api/2.1/unity-catalog/tables/main.foo.bar", - Response: PartitionInfo{}, + Resource: "/api/2.1/unity-catalog/tables/main.foo.bar?", + Response: catalog.TableInfo{}, }, }, Create: true, @@ -1477,8 +1502,8 @@ func TestResourceSqlTableCreateTableWithIdentityColumn_ExistingSQLWarehouse(t *t }, { Method: "GET", - Resource: "/api/2.1/unity-catalog/tables/main.foo.bar", - Response: PartitionInfo{}, + Resource: "/api/2.1/unity-catalog/tables/main.foo.bar?", + Response: catalog.TableInfo{}, }, }, Create: true, @@ -1548,8 +1573,8 @@ func TestResourceSqlTableReadTableWithIdentityColumn_ExistingSQLWarehouse(t *tes }, { Method: "GET", - Resource: "/api/2.1/unity-catalog/tables/main.foo.bar", - Response: PartitionInfo{}, + Resource: "/api/2.1/unity-catalog/tables/main.foo.bar?", + Response: catalog.TableInfo{}, }, }, ID: "main.foo.bar", @@ -1562,9 +1587,6 @@ func TestResourceSqlTableReadTableWithIdentityColumn_ExistingSQLWarehouse(t *tes }) } -func getPtr(num int) *int { - return &num -} func TestResourceSqlTableReadTableWithPartitionColumn_ExistingSQLWarehouse(t *testing.T) { qa.ResourceFixture{ CommandMock: func(commandStr string) common.CommandResults { @@ -1623,16 +1645,18 @@ func TestResourceSqlTableReadTableWithPartitionColumn_ExistingSQLWarehouse(t *te }, { Method: "GET", - Resource: "/api/2.1/unity-catalog/tables/main.foo.bar", - Response: PartitionInfo{ - ColumnInfos: []ColumnPartitionInfo{ + Resource: "/api/2.1/unity-catalog/tables/main.foo.bar?", + Response: catalog.TableInfo{ + Columns: []catalog.ColumnInfo{ { - Name: "id", - PartitionIndex: getPtr(1), + Name: "id", + PartitionIndex: 1, + ForceSendFields: []string{"PartitionIndex"}, }, { - Name: "name", - PartitionIndex: getPtr(0), + Name: "name", + PartitionIndex: 0, + ForceSendFields: []string{"PartitionIndex"}, }, { Name: "number", @@ -1714,8 +1738,8 @@ func TestResourceSqlTableCreateTable_OnlyManagedProperties(t *testing.T) { }, { Method: "GET", - Resource: "/api/2.1/unity-catalog/tables/main.foo.bar", - Response: PartitionInfo{}, + Resource: "/api/2.1/unity-catalog/tables/main.foo.bar?", + Response: catalog.TableInfo{}, }, }, Create: true, From c72f22cbc273d78c8b012f2b1696956fae883bb5 Mon Sep 17 00:00:00 2001 From: Vuong Date: Tue, 25 Feb 2025 22:34:58 +0800 Subject: [PATCH 5/5] next_changelog --- NEXT_CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEXT_CHANGELOG.md b/NEXT_CHANGELOG.md index 0dad6ba04..5ed0cb73b 100644 --- a/NEXT_CHANGELOG.md +++ b/NEXT_CHANGELOG.md @@ -9,7 +9,7 @@ ### Bug Fixes - * Populate `partitions` when reading `databricks_sql_table` ([#4483](https://github.com/databricks/terraform-provider-databricks/pull/4483)). + * Populate `partitions` when reading `databricks_sql_table` ([#4486](https://github.com/databricks/terraform-provider-databricks/pull/4486)). * Delete `databricks_sql_endpoint` that failed to start ([#4520](https://github.com/databricks/terraform-provider-databricks/pull/4520)) ### Documentation