Skip to content

Commit b4e119e

Browse files
abest-tznkvuong
andauthored
fix: do not attempt to delete default schema for foriegn catalogs (#2622)
* fix: do not attempt to delete default schema for foriegn catalogs * fix: do not attempt to delete default schema for foriegn catalogs * fix: add test for foriegn catalog create * better comment Co-authored-by: vuong-nguyen <[email protected]> * fix: formatting --------- Co-authored-by: vuong-nguyen <[email protected]>
1 parent 55b47c7 commit b4e119e

File tree

2 files changed

+55
-2
lines changed

2 files changed

+55
-2
lines changed

catalog/resource_catalog.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ func ResourceCatalog() *schema.Resource {
6464
if err != nil {
6565
return err
6666
}
67-
// only remove catalog default schema for non-Delta Sharing catalog
68-
if ci.ShareName == "" {
67+
// only remove catalog default schema for standard catalog (e.g. non-Delta Sharing, non-foreign)
68+
if ci.ShareName == "" && ci.ConnectionName == "" {
6969
if err := w.Schemas.DeleteByFullName(ctx, ci.Name+".default"); err != nil {
7070
return fmt.Errorf("cannot remove new catalog default schema: %w", err)
7171
}

catalog/resource_catalog_test.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,59 @@ func TestCatalogCreateAlsoDeletesDefaultSchema(t *testing.T) {
6868
}.ApplyNoError(t)
6969
}
7070

71+
func TestCatalogCreateWithForiegnCatalogDoesNotDeleteDefaultSchema(t *testing.T) {
72+
qa.ResourceFixture{
73+
Fixtures: []qa.HTTPFixture{
74+
{
75+
Method: "POST",
76+
Resource: "/api/2.1/unity-catalog/catalogs",
77+
ExpectedRequest: catalog.CreateCatalog{
78+
Name: "a",
79+
Comment: "b",
80+
Properties: map[string]string{
81+
"c": "d",
82+
},
83+
ConnectionName: "g", // this indicates a foriegn catalog
84+
},
85+
Response: catalog.CatalogInfo{
86+
Name: "a",
87+
Comment: "b",
88+
Properties: map[string]string{
89+
"c": "d",
90+
},
91+
MetastoreId: "e",
92+
Owner: "f",
93+
ConnectionName: "g",
94+
},
95+
},
96+
{
97+
Method: "GET",
98+
Resource: "/api/2.1/unity-catalog/catalogs/a?",
99+
Response: catalog.CatalogInfo{
100+
Name: "a",
101+
Comment: "b",
102+
Properties: map[string]string{
103+
"c": "d",
104+
},
105+
MetastoreId: "e",
106+
Owner: "f",
107+
ConnectionName: "g",
108+
},
109+
},
110+
},
111+
Resource: ResourceCatalog(),
112+
Create: true,
113+
HCL: `
114+
name = "a"
115+
comment = "b"
116+
properties = {
117+
c = "d"
118+
}
119+
connection_name = "g"
120+
`,
121+
}.ApplyNoError(t)
122+
}
123+
71124
func TestCatalogCreateWithOwnerAlsoDeletesDefaultSchema(t *testing.T) {
72125
qa.ResourceFixture{
73126
Fixtures: []qa.HTTPFixture{

0 commit comments

Comments
 (0)