fix(ingest/adf): resolve real database/catalog names and platform instances for cross-platform lineage

Merged
BR
1mo ago
+7916-912

Summary

While validating #19488's fix against a real customer tenant, we found a related but distinct lineage bug: activities pointing at MSSQL, MySQL, Databricks, and other platforms were emitting under-qualified or garbage dataset names (e.g. schema.table instead of database.schema.table, or a raw Python dict repr when a typeProperty used unresolved ADF dynamic content).

Root cause: ADF's own API rarely exposes enough to fully qualify a lineage target the way the real platform's own DataHub source would. The existing table-name resolution (dataset parameter defaults + activity-level overrides) never extended to the database/catalog/platform-instance segments, and several dynamic-content shapes (parameterized linked services, factory-level global parameters, ForEach per-iteration values) weren't resolved at all.

What changed

Generalizes lineage-target resolution across every supported relational/Databricks platform:

  • MSSQL/Synapse/ODBC: parses Initial Catalog= / Database= from the connection string, through the same activity-override > dataset-default > linked-service-default precedence already used for table names — including through "parameterized" linked services that reference their own declared parameter rather than a literal.
  • MySQL/PostgreSQL: reads the standalone database typeProperty (a different shape than the connection-string case above).
  • Oracle: best-effort heuristic recovers the service name from a service/sid-named parameter referenced inside the free-form server connect string, since Oracle exposes no database field at all.
  • Databricks: no catalog or metastore field exists anywhere in ADF's API. Adds databricks_default_catalog / databricks_catalog_map config, since there's no reliable way to distinguish a legacy hive_metastore workspace from a Unity Catalog workspace with an arbitrary catalog name — the connector never guesses this.
  • Databricks platform_instance is now auto-derived from the linked service's workspace URL (matching how DataHub's own Unity Catalog source derives it from workspace_url), including resolving it through a factory-level global parameter reference (@pipeline().globalParameters.X) — a previously-unhandled class of ADF dynamic content, now resolved wherever a value can reference one.
  • Fixes a latent bug in database resolution: it only checked the linked service's own declared parameter default, ignoring that the same dataset/linked-service pair is commonly reused across pipelines with a different literal database name supplied per-activity. Now resolved via the same activity-override > dataset-default > linked-service-default chain used everywhere else.
  • Extracted the duplicated dataset → linked-service → platform → platform-instance lookup chain (previously copy-pasted between the static and query-based lineage resolution paths) into a single shared _resolve_dataset_platform_context helper.

Confidentiality note: all real-tenant data used to discover and verify these bugs (subscription/tenant IDs, pipeline/table names, hostnames) was used only for local, transient verification and never committed. All fixtures and tests use synthetic placeholder names.

Before / After (illustrative, not the real customer's data)

Before: urn:li:dataset:(urn:li:dataPlatform:databricks,cubes.orders,PROD)
After:  urn:li:dataset:(urn:li:dataPlatform:databricks,adb-1234567890123456.cubes.orders,PROD)
        (or, with databricks_catalog_map configured:)
        urn:li:dataset:(urn:li:dataPlatform:databricks,adb-1234567890123456.my_metastore.my_catalog.cubes.orders,PROD)

Test plan

  • 134 unit + integration tests pass (tests/unit/azure_data_factory/, tests/integration/azure_data_factory/)
  • mypy clean on all changed connector source files
  • ./gradlew :metadata-ingestion:lintFix — clean
  • Verified end-to-end against a real customer tenant (resolved database names, platform instances, and catalog/metastore mapping all confirmed correct; no customer data committed)

Docs

  • docs/how/updating-datahub.md — documents the Databricks platform_instance auto-derivation as a behavior change, with an action item for affected users
  • metadata-ingestion/docs/sources/azure-data-factory/azure-data-factory_post.md — new "Databricks Catalog and Metastore" section covering the new config

Checklist

  • The PR conforms to DataHub's Contributing Guideline (PR Title Format)
  • Tests for the changes have been added/updated
  • Docs related to the changes have been added/updated
  • Breaking changes documented in docs/how/updating-datahub.md

Builds on #19488.

🤖 Generated with Claude Code


Summary by cubic

Fixes ADF lineage so dataset targets get fully qualified database/catalog names and platform instances, and recovers column-level lineage for dynamic (ForEach-looped) Copy activities.

Platform and database resolution

  • Both static and per-run query paths now qualify database/catalog names; the static _resolve_dataset_urn path previously stayed under-qualified.
  • MSSQL/Synapse/ODBC parses Initial Catalog=/Database= from connection strings through the activity-override > dataset-default > linked-service-default precedence already used for table names.
  • MySQL/PostgreSQL read the standalone database typeProperty; Oracle best-effort recovers the service name from the free-form server connect string.
  • Databricks adds databricks_default_catalog and databricks_catalog_map config; platform_instance is only derived alongside a configured metastore, matching the Unity Catalog source, with an explicit platform_instance_map entry winning or opting out.
  • Database resolution honors per-activity literal overrides; all segments resolve through a shared _resolve_dataset_platform_context helper, which no longer drops non-parameterized sibling inputs/outputs when another reference gets substituted.
  • MongoDB/CosmosDB datasets resolve via their collection/database properties, and Data Flow sources/sinks forward dataset parameters.
  • Maps newly supported linked service types (V2 and Amazon RDS variants, Mongo, Cassandra, Couchbase, Informix, Presto, MariaDB, SapHana, GoogleSheets) to their DataHub platforms.
  • The global-parameters API is best-effort: a 403/404 logs a warning instead of skipping the whole factory, and dataset-parameter defaults and connection-string/database reads now unwrap Expression-dict wrapping and resolve global-parameter references like sibling paths already did.
  • Activity lookup now uses the shared activity walker instead of an id()-only BFS, which could skip a nested activity when a freed activity's id got reused.

Column-level lineage and migration

  • Recovers column lineage for ForEach-looped Copy activities from the resolved per-run query text, pairing selected columns with same-named sink columns; skipped when the activity has an explicit translator.
  • Dynamic translators come from the activity's own resolved ActivityRun.input.translator, falling back to query-derived auto-mapping when the translator is empty; plain same-name lineage applies when it resolves to nothing.
  • Expands unambiguous single-table SELECT * queries using the source table's schema from DataHub's graph with same-name mapping; rejects CROSS/OUTER APPLY and other table-valued joins, and normalizes v2 schema fieldPath values before matching.
  • Silently degrades when no graph is configured or the table is unknown; include_column_lineage=False disables the dynamic recovery path too, and dynamic augmentation preserves existing fine-grained lineage and no longer erases inputDatajobs edges written for ExecutePipeline activities, whose child DataFlow URN now includes the ADF platform_instance so the dynamic rewrite matches the real child job.
  • Adds the sqlglot dependency to the azure-data-factory extra.
  • Default database/catalog qualification and platform_instance derivation can change existing dataset URNs on SQL Server, MySQL, PostgreSQL, MongoDB, and Databricks; if your recipe sets its own platform_instance, configure platform_instance_map instead — see docs/how/updating-datahub.md.