Skip to content

Commit 7385f59

Browse files
authored
Exporter: Add UC support for DLT pipelines (#3494)
Now `catalog` and `target` fields are now resolved into actual references to UC objects (catalogs & schemas)
1 parent ea66fb8 commit 7385f59

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

exporter/exporter_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2472,7 +2472,10 @@ func TestIncrementalDLTAndMLflowWebhooks(t *testing.T) {
24722472
PipelineID: "def",
24732473
Name: "def",
24742474
LastModified: 1690156900000,
2475-
Spec: &pipelines.PipelineSpec{},
2475+
Spec: &pipelines.PipelineSpec{
2476+
Target: "default",
2477+
Catalog: "main",
2478+
},
24762479
},
24772480
ReuseRequest: true,
24782481
},

exporter/importables.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1919,6 +1919,12 @@ var resourcesMap map[string]importable = map[string]importable{
19191919
var pipeline pipelines.PipelineSpec
19201920
s := ic.Resources["databricks_pipeline"].Schema
19211921
common.DataToStructPointer(r.Data, s, &pipeline)
1922+
if pipeline.Catalog != "" && pipeline.Target != "" {
1923+
ic.Emit(&resource{
1924+
Resource: "databricks_schema",
1925+
ID: pipeline.Catalog + "." + pipeline.Target,
1926+
})
1927+
}
19221928
for _, lib := range pipeline.Libraries {
19231929
if lib.Notebook != nil {
19241930
ic.emitNotebookOrRepo(lib.Notebook.Path)
@@ -1983,6 +1989,9 @@ var resourcesMap map[string]importable = map[string]importable{
19831989
return numLibraries == 0
19841990
},
19851991
Depends: []reference{
1992+
{Path: "catalog", Resource: "databricks_catalog"},
1993+
{Path: "target", Resource: "databricks_schema", Match: "name",
1994+
IsValidApproximation: dltIsMatchingCatalogAndSchema, SkipDirectLookup: true},
19861995
{Path: "cluster.aws_attributes.instance_profile_arn", Resource: "databricks_instance_profile"},
19871996
{Path: "cluster.init_scripts.dbfs.destination", Resource: "databricks_dbfs_file", Match: "dbfs_path"},
19881997
{Path: "cluster.init_scripts.volumes.destination", Resource: "databricks_file"},

exporter/util.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1477,3 +1477,21 @@ func (ic *importContext) emitWorkspaceObjectParentDirectory(r *resource) {
14771477
r.AddExtraData(ParentDirectoryExtraKey, directoryPath)
14781478
}
14791479
}
1480+
1481+
func dltIsMatchingCatalogAndSchema(ic *importContext, res *resource, ra *resourceApproximation, origPath string) bool {
1482+
res_catalog_name := res.Data.Get("catalog").(string)
1483+
if res_catalog_name == "" {
1484+
return false
1485+
}
1486+
res_schema_name := res.Data.Get("target").(string)
1487+
ra_catalog_name, cat_found := ra.Get("catalog_name")
1488+
ra_schema_name, schema_found := ra.Get("name")
1489+
if !cat_found || !schema_found {
1490+
log.Printf("[WARN] Can't find attributes in approximation: %s %s, catalog='%v' (found? %v) schema='%v' (found? %v). Resource: %s, catalog='%s', schema='%s'",
1491+
ra.Type, ra.Name, ra_catalog_name, cat_found, ra_schema_name, schema_found, res.Resource, res_catalog_name, res_schema_name)
1492+
return true
1493+
}
1494+
1495+
result := ra_catalog_name.(string) == res_catalog_name && ra_schema_name.(string) == res_schema_name
1496+
return result
1497+
}

0 commit comments

Comments
 (0)