Skip to content

Commit b1311f5

Browse files
authored
Migrate databricks_views data source to Go SDK (#2073)
1 parent 104bc7d commit b1311f5

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

catalog/data_views.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,26 @@ package catalog
33
import (
44
"context"
55

6+
"github.com/databricks/databricks-sdk-go"
7+
"github.com/databricks/databricks-sdk-go/service/unitycatalog"
68
"github.com/databricks/terraform-provider-databricks/common"
79
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
810
)
911

1012
func DataSourceViews() *schema.Resource {
11-
type viewsData struct {
13+
return common.WorkspaceData(func(ctx context.Context, data *struct {
1214
CatalogName string `json:"catalog_name"`
1315
SchemaName string `json:"schema_name"`
1416
Ids []string `json:"ids,omitempty" tf:"computed,slice_set"`
15-
}
16-
return common.DataResource(viewsData{}, func(ctx context.Context, e any, c *common.DatabricksClient) error {
17-
data := e.(*viewsData)
18-
tablesAPI := NewTablesAPI(ctx, c)
19-
tables, err := tablesAPI.listTables(data.CatalogName, data.SchemaName)
17+
}, w *databricks.WorkspaceClient) error {
18+
19+
tables, err := w.Tables.ListAll(ctx, unitycatalog.ListTablesRequest{CatalogName: data.CatalogName, SchemaName: data.SchemaName})
2020
if err != nil {
2121
return err
2222
}
23-
for _, v := range tables.Tables {
23+
for _, v := range tables {
2424
if v.TableType == "VIEW" {
25-
data.Ids = append(data.Ids, v.FullName())
25+
data.Ids = append(data.Ids, v.FullName)
2626
}
2727
}
2828
return nil

catalog/data_views_test.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package catalog
33
import (
44
"testing"
55

6+
"github.com/databricks/databricks-sdk-go/service/unitycatalog"
67
"github.com/databricks/terraform-provider-databricks/qa"
78
)
89

@@ -11,19 +12,21 @@ func TestViewsData(t *testing.T) {
1112
Fixtures: []qa.HTTPFixture{
1213
{
1314
Method: "GET",
14-
Resource: "/api/2.1/unity-catalog/tables/?catalog_name=a&schema_name=b",
15-
Response: Tables{
16-
Tables: []TableInfo{
15+
Resource: "/api/2.1/unity-catalog/tables?catalog_name=a&schema_name=b",
16+
Response: unitycatalog.ListTablesResponse{
17+
Tables: []unitycatalog.TableInfo{
1718
{
1819
CatalogName: "a",
1920
SchemaName: "b",
2021
Name: "c",
22+
FullName: "a.b.c",
2123
TableType: "MANAGED",
2224
},
2325
{
2426
CatalogName: "a",
2527
SchemaName: "b",
2628
Name: "d",
29+
FullName: "a.b.d",
2730
TableType: "VIEW",
2831
},
2932
},

0 commit comments

Comments
 (0)