feat(ingest/unity): ingest metric views as semantic models and metrics

Merged
AC
4d ago
+3464-76

Summary

Databricks Unity Catalog metric views can now be ingested as first-class semanticModel and metric entities, using the same mapping and switch as Snowflake semantic views.

Each metric view becomes:

Metric view YAMLDataHub
the metric viewsemanticModel, with the YAML as its native definition
source and each joins[].name, nested joins includedone logical dataset (subtype Semantic Model Dataset), with upstream and column-level lineage to the physical table
joins[].on / usingrelationships between the logical datasets
dimensionsannotated fields on the logical dataset their expr reads
measuresone metric each, upstream of the logical datasets its expr reads
MEASURE(name) inside a measurederivedFrom edge to that metric

Switch

emit_semantic_model_entities is tri-state and resolved with the shared semantic_model_gate, as for Snowflake. Left unset, it turns on against DataHub Cloud 2.1.0 or later with Metrics enabled, and stays off on OSS and on runs with no server connection. true requests it and false keeps Metric View datasets. It only applies with include_metric_views: true.

Behaviour when on

  • Replaces the dataset, as Snowflake does: the Metric View dataset is not emitted, and stateful ingestion removes previously ingested ones.
  • Usage and profiling skip metric views, since they would otherwise recreate that dataset.
  • Genie agents that use a metric view get lineage to its logical datasets, because their lineage aspect only takes dataset upstreams.
  • Fallback: a metric view whose YAML can't be read is still emitted as a dataset, and the report says so.

Not inventing what the YAML doesn't say

  • A dimension whose expr reads one table goes on that table's logical dataset; unqualified columns read source. One that reads several tables goes on source, the grain the metric view is computed at, and is counted in the report. Column-level lineage still points at every column it reads.
  • A join becomes a relationship only when its on compares columns qualified with both tables' names, or it has a using list. Join keys not covered by a dimension are added as fields. Joins with unqualified on columns are skipped and reported rather than guessed. Cardinality is left unset because the YAML doesn't state it.
  • The view filter and a measure's window change what a measure computes but are not part of expr, so they are kept as trailing comments on the metric expression, as the dbt source does for filters and cumulative windows.

Not included

  • No migration of edits made on existing Metric View datasets (owners, docs, terms). Snowflake has datahub migrate snowflake-semantic-views for this; a Unity version would be a follow-up.

Test plan

  • New integration golden (test_metric_view_ingestion_semantic_model) on the existing metric view mock data. Existing metric view goldens are unchanged.
  • Unit tests for:
    • the dataset being replaced, and metric views staying out of table_refs;
    • dimension placement, including the multi-table case;
    • relationships from qualified on and from using, plus skipping unqualified on;
    • metric upstreams and derivedFrom, and the filter comment;
    • fallback on unreadable YAML;
    • switch resolution;
    • Genie redirect.
  • 560 Unity unit and integration tests pass. mypy is clean; ruff and markdown formatting run via Gradle.

Checklist

  • PR title follows the Contributing Guideline
  • Tests added
  • Docs updated (Unity connector docs, Metrics & Semantic Models guides)
  • Breaking change entry added to docs/how/breaking-changes.md (auto-enables on DataHub Cloud for include_metric_views users)

šŸ¤– Generated with Claude Code


Summary by cubic

Databricks Unity Catalog metric views can now be ingested as semanticModel and metric entities instead of Metric View datasets, using the same mapping and switch as Snowflake semantic views.

Switch and behavior

  • emit_semantic_model_entities is tri-state; unset, it auto-enables on DataHub Cloud 2.1.0+ with Metrics enabled and stays off on OSS and connectionless runs, and only applies with include_metric_views: true.
  • When on, the Metric View dataset is not emitted, stateful ingestion removes previously ingested ones, and usage and profiling skip metric views so profiles no longer recreate the replaced dataset URN.
  • Genie agents and notebooks that use a metric view get lineage to its logical datasets, and a metric view whose YAML can't be read is still emitted as a dataset.
  • Table lineage pointing at a metric view now points at its logical datasets; a logical dataset whose YAML source is a subquery takes its upstreams from Catalog table lineage when it's the only unresolved table, and is reported otherwise.
  • Skipped YAML join entries are reported, and emit_semantic_model_entities warns when metric views are not ingested.
  • Edits made on existing Metric View datasets (owners, docs, terms) are not migrated; a Unity version of the Snowflake migration command would be a follow-up.

Mapping

  • Each metric view becomes a semanticModel with the YAML as native definition, one logical dataset per source/joins entry with lineage, and one metric per measure, with derivedFrom edges for MEASURE() references.
  • Relationships are created only when a join's on qualifies columns on both tables or it has a using list; unqualified joins are skipped and reported.
  • Dimensions are annotated fields on the logical dataset their expr reads; dimensions reading multiple tables go on source.
  • View filters and measure windows become trailing comments on metric expressions.
  • Logical dataset browse paths drop the self-entry that previously added the dataset's own name to the path.