Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
968862a
refactor(sdk): share dataset URN parsing, browse-path and structured-…
sgomezvillamor Dec 1, 2026
c9cdcb9
feat(sdk): column-level lineage on metrics
sgomezvillamor Dec 1, 2026
a56cb31
feat(sdk): declare upstream metrics on charts, dashboards and datasets
sgomezvillamor Dec 1, 2026
676d966
feat(sdk): external URL, subtype, browse path and field metadata for …
sgomezvillamor Dec 1, 2026
a081564
feat(sdk): metric lineage in the lineage client
sgomezvillamor Dec 1, 2026
bcfe6c5
docs(sdk): examples and docs for metric lineage
sgomezvillamor Dec 1, 2026
a6d203c
docs: link breaking-change entry to its PR
sgomezvillamor Dec 1, 2026
2e2fc42
feat(ingest/unity,microstrategy): metric column lineage
sgomezvillamor Dec 1, 2026
9076019
fix(ingest/unity): match measure columns on dimension expressions only
sgomezvillamor Dec 1, 2026
7c5f6ae
fix(sdk): keep get_lineage working on servers without the Metric type
sgomezvillamor Dec 1, 2026
6d9198a
fix(sdk): keep edge metadata in set_upstream_metrics
sgomezvillamor Dec 1, 2026
c4a6af0
fix(sdk): validate derived_from inputs as metric URNs
sgomezvillamor Dec 1, 2026
b3700f3
docs(sdk): point to connector pages for metric column lineage support
sgomezvillamor Dec 1, 2026
640651a
Merge remote-tracking branch 'origin/feat-sdk-semanticmodels' into fe…
sgomezvillamor Dec 1, 2026
f7750a7
Merge remote-tracking branch 'origin/master' into feat-unity-mstr-met…
sgomezvillamor Dec 3, 2026
7f39f16
fix(ingest/unity): honour include_column_lineage for metric column li…
sgomezvillamor Dec 4, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ Each metric view then becomes:
- A **Semantic Model** holding the YAML as its definition and the `joins` as relationships.
- A **logical dataset** (subtype `Semantic Model Dataset`) named `<metric view>.source` for the `source` table, and one named `<metric view>.<join name>` per join, nested joins included. Each has upstream lineage to the table it reads, with column-level lineage when `include_column_lineage` is on. A subquery `source` becomes the logical dataset's view definition. A `source` that is a subquery, or a name that is not a 2- or 3-part table name, takes its upstreams from Unity Catalog table lineage, provided it is the only table in the metric view that cannot be read as a table name; otherwise it has no upstreams and the report says so.
- **Dimensions** as fields on the logical dataset their `expr` reads. They can be declared under `fields:`, the key Databricks documents, or under its synonym `dimensions:`. Unqualified columns read `source`. A dimension reading columns from several tables is placed on `source`, the grain the metric view is computed at, and the report counts it.
- A **Metric** per measure, downstream of the logical datasets its `expr` reads (`COUNT(1)` reads `source`). `MEASURE(name)` references become metric-to-metric `derivedFrom` lineage. The view's `filter` and a measure's `window` are kept as trailing comments on the expression, since neither is part of `expr`.
- A **Metric** per measure, downstream of the logical datasets its `expr` reads (`COUNT(1)` reads `source`). With `include_column_lineage` on, its column lineage (`fieldUpstreams`) points at the logical dataset fields its `expr` reads: a dimension whose `expr` is just that column, or a join key. A column that no dimension or join key exposes has no field to point at, so it gets no column edge and is counted in `num_metric_view_measure_columns_without_field`; the dataset edge still covers it. `MEASURE(name)` references become metric-to-metric `derivedFrom` lineage. The view's `filter` and a measure's `window` are kept as trailing comments on the expression, since neither is part of `expr`.

A join becomes a relationship when its `on` condition compares columns qualified with the two tables' names (for example `source.customer_id = customer.id`) or when it has a `using` list. Join columns that the metric view does not declare as fields are added to the logical datasets as join keys, not as dimensions, since the metric view cannot be grouped by them. A join whose condition uses unqualified columns does not say which table each column belongs to, so it is left out of the relationships and reported. The relationship's cardinality comes from the join's `cardinality`: `many_to_one`, or no value (the Databricks default), gives many-to-one, and `one_to_many` gives one-to-many, reading from the parent table to the joined one. Any other value leaves the cardinality unset and is reported. A join whose `on` condition is not valid SQL is also left out of the relationships, and the report includes the parse error.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ Set `emit_semantic_model_entities: true` to additionally emit each project's sch

- One `semanticModel` entity per project.
- One logical dataset (subtype `Semantic Model Dataset`) per MicroStrategy logical table, with attributes emitted as `Dimension`-annotated fields and facts as `Measure`-annotated fields. Each logical dataset carries coarse upstream lineage to its physical warehouse table when a warehouse context is resolved for that table (see Dependency and Model Lineage Enrichment). A logical view (a logical table defined by SQL) takes its upstreams from parsing that SQL instead. Tables the SQL names without the database or schema its platform needs, when the datasource gives no default, are skipped (`sql_upstreams_skipped_unqualified`), as is `DUAL` on Oracle, MySQL and MariaDB. A physical table whose name cannot be fully qualified, or a logical view with no SQL, gets no upstream (`semantic_model_tables_without_warehouse_name`).
- One `metric` entity per project metric (Base, Derived/Compound, and Consolidated), with lineage resolved from the metric's own expression: a Base metric's `metricUpstreams` point at the logical dataset(s) backing the facts/attributes it reads; a Derived/Compound metric's `metricRelationships.derivedFrom` points at the `metric` entities it is computed from; a Consolidated metric resolves its consolidation's attribute references (one extra API call per distinct consolidation, cached across metrics that share one) and sets `metricUpstreams` from those.
- One `metric` entity per project metric (Base, Derived/Compound, and Consolidated), with lineage resolved from the metric's own expression: a Base metric's `metricUpstreams` point at the logical dataset(s) backing the facts/attributes it reads; a Derived/Compound metric's `metricRelationships.derivedFrom` points at the `metric` entities it is computed from; a Consolidated metric resolves its consolidation's attribute references (one extra API call per distinct consolidation, cached across metrics that share one) and sets `metricUpstreams` from those. Each metric also carries column lineage (`metricUpstreams.fieldUpstreams`) to the fact and attribute fields it reads, on every logical dataset that exposes them. A fact or attribute that no logical table exposes is counted in `semantic_model_metric_upstream_fields_unresolved`.
- Relationships between logical datasets, derived from MicroStrategy's attribute hierarchy API: an attribute shared across more than one logical table triggers a lookup of that attribute's parent/child relationships, and a `semanticModelRelationship` is emitted when the two ends resolve to different tables (a hierarchy encoded entirely within one lookup table's columns has nothing to join, so no relationship is emitted for that case).

This is additive: it does not change the dashboard/report/dataset emission described elsewhere on this page, and is disabled by default. It requires `extract_model_lineage` access to the MicroStrategy modeling APIs (the same access `extract_model_lineage` already needs) and a DataHub server that registers `semanticModel`/`metric` (Cloud >= 2.1.0, or OSS with `METRICS_ENABLED=true`).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1106,12 +1106,22 @@ def _build_metric(
for referenced_metric_id in metric_metric_ids_from_model(model)
],
)
upstream_ids = {*fact_ids, *attribute_ids}
# A fact or attribute that no logical table exposes has no field to
# point at, and no dataset upstream either.
self.report.report_semantic_model_metric_upstream_fields_unresolved(
sum(
1
for upstream_id in upstream_ids
if upstream_id not in object_field_urns
)
)
# Written even when empty so a re-ingest clears stale column edges.
metric.set_upstream_fields(
sorted(
{
field_urn
for upstream_id in [*fact_ids, *attribute_ids]
for upstream_id in upstream_ids
for field_urn in object_field_urns.get(upstream_id, [])
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,9 @@ class MicroStrategyReport(StaleEntityRemovalSourceReport):
semantic_model_attribute_relationship_api_failures: int = 0
semantic_model_consolidation_api_failures: int = 0
semantic_model_metric_search_api_failures: int = 0
# Facts or attributes a metric reads that no logical table exposes, so no
# column edge (and no dataset upstream) could be emitted for them.
semantic_model_metric_upstream_fields_unresolved: int = 0
sql_parses_executed: int = 0
sql_parse_cache_hits: int = 0
# Reuses of a failed parse. The failure itself is counted once per distinct SQL.
Expand Down Expand Up @@ -763,6 +766,12 @@ def report_semantic_model_column_lineage_fields(self, count: int) -> None:
with self._lock:
self.semantic_model_column_lineage_fields += count

def report_semantic_model_metric_upstream_fields_unresolved(
self, count: int
) -> None:
with self._lock:
self.semantic_model_metric_upstream_fields_unresolved += count

def report_sql_parse_executed(self, statements: int) -> None:
with self._lock:
self.sql_parses_executed += 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ class _LogicalTable:
# from the YAML (a subquery or a 1-part name).
lineage_fallback: List[TableReference] = field(default_factory=list)
fields: Dict[str, SemanticFieldInput] = field(default_factory=dict)
# Field path -> the expression it was declared with, used to match join keys
# onto an existing dimension rather than adding a duplicate field.
field_exprs: Dict[str, str] = field(default_factory=dict)
# Lowercased column name -> the field whose expression is just that column.
# Maps a join key or a measure's input column onto the field exposing it.
column_fields: Dict[str, str] = field(default_factory=dict)
lineages: List[FineGrainedLineageClass] = field(default_factory=list)


Expand All @@ -144,6 +144,9 @@ class _ParsedExpression:
keys: Set[str] = field(default_factory=set)
# (physical table, column) of each column read, for column-level lineage.
columns: List[Tuple[TableReference, str]] = field(default_factory=list)
# (logical table key, lowercased column) of each column read, to point a
# measure's column lineage at the logical dataset field exposing it.
key_columns: Set[Tuple[str, str]] = field(default_factory=set)
# Qualifiers that name neither `source`, a join, nor a struct column of one.
unknown_tables: Set[str] = field(default_factory=set)
parse_error: Optional[Exception] = None
Expand Down Expand Up @@ -671,8 +674,9 @@ def _add_dimension(
is_time_dimension=native_type.lower().startswith(_TIME_TYPE_PREFIXES),
ai_context=_ai_context(entry),
)
if expr_str:
target.field_exprs[name] = expr_str
column = _bare_column(expr_str, key) if expr_str else None
if column is not None:
target.column_fields.setdefault(column, name)

if self.config.include_column_lineage:
self._add_lineage(
Expand Down Expand Up @@ -762,6 +766,7 @@ def _parse_expression(
parsed.unknown_tables.add(qualifier or parent)
continue
parsed.keys.add(key)
parsed.key_columns.add((key, column_name.lower()))
ref = logical_tables[key].ref
# A `source` that is a subquery or an unresolved name has no table
# to point column lineage at.
Expand Down Expand Up @@ -913,13 +918,13 @@ def _join_key_field(
dataset_urns: Dict[str, str],
) -> str:
"""Field path for a join key, adding the key as a field when no dimension covers it."""
column_lower = column.lower()
qualified = f"{logical_table.key or SOURCE_ALIAS}.{column_lower}"
for field_path, expr in logical_table.field_exprs.items():
if expr.strip().lower() in (column_lower, qualified):
return field_path
existing = logical_table.column_fields.get(column.lower())
if existing is not None:
return existing
# A dimension may already carry the key's name while transforming
# another column. Reuse it rather than overwrite it with the raw key.
for field_path in logical_table.fields:
if field_path.lower() == column_lower:
if field_path.lower() == column.lower():
return field_path

# Join keys are columns of the logical table the YAML names in `on` /
Expand All @@ -936,7 +941,7 @@ def _join_key_field(
dialect=DialectClass.DATABRICKS,
),
)
logical_table.field_exprs[column] = column
logical_table.column_fields[column.lower()] = column
if self.config.include_column_lineage and logical_table.ref is not None:
self._add_lineage(
logical_table,
Expand Down Expand Up @@ -1006,6 +1011,33 @@ def _logical_dataset(
dataset.set_custom_properties(custom_properties)
return dataset

def _measure_fields(
self,
key_columns: Set[Tuple[str, str]],
logical_tables: Dict[str, _LogicalTable],
dataset_urns: Dict[str, str],
) -> Set[str]:
"""schemaField URNs of the logical-dataset fields a measure reads.

A logical dataset only carries the view's dimensions and join keys, so a
column that neither exposes has no field to point at. It is counted, not
warned about: the measure's dataset upstream still covers it.
"""
fields: Set[str] = set()
without_field = 0
for key, column in key_columns:
field_path = logical_tables[key].column_fields.get(column)
if field_path is None:
without_field += 1
else:
fields.add(make_schema_field_urn(dataset_urns[key], field_path))
if without_field:
self._report_later(lambda: self._count_columns_without_field(without_field))
return fields

def _count_columns_without_field(self, count: int) -> None:
self.report.num_metric_view_measure_columns_without_field += count

def _metrics(
self,
*,
Expand Down Expand Up @@ -1036,10 +1068,20 @@ def _metrics(
references[key] = measure_refs

upstream_keys: Set[str] = set()
# Unset, not [], when column lineage is off, as the logical datasets
# leave fineGrainedLineages unset. metricUpstreams is written whole
# either way, so DataHub ends up with no column edges in both cases.
upstream_fields: Optional[Set[str]] = (
set() if self.config.include_column_lineage else None
)
if expr_str:
parsed = self._parse_expression(expr_str, logical_tables)
upstream_keys = parsed.keys
expression_issues.record(name, parsed)
if self.config.include_column_lineage:
upstream_fields = self._measure_fields(
parsed.key_columns, logical_tables, dataset_urns
)
# A measure such as COUNT(1) reads no column but still aggregates
# the rows of `source`; one built only from other measures reads
# through them via derivedFrom instead. An expression that does
Expand Down Expand Up @@ -1072,6 +1114,9 @@ def _metrics(
else None
),
upstream_datasets=sorted(dataset_urns[k] for k in upstream_keys),
upstream_fields=(
sorted(upstream_fields) if upstream_fields is not None else None
),
ai_context=_ai_context(entry),
owners=context.owners,
domain=context.domain_urn,
Expand Down Expand Up @@ -1124,6 +1169,23 @@ def _description(comment: Optional[str]) -> Optional[str]:
return comment if comment is not None and comment.strip() else None


def _bare_column(expr: str, table_key: str) -> Optional[str]:
"""Lowercased column name when `expr` is just a column of the given logical table.

Parsed rather than compared as text, so quoting and qualifying the column
(`order_date`, source.`order_date`) are the same column. A struct field
(`source.address.city`) is not the column itself.
"""
try:
tree = sqlglot.parse_one(expr, dialect="databricks")
except _SQLGLOT_PARSE_ERRORS:
return None
if not isinstance(tree, sqlglot_exp.Column) or tree.db:
return None
qualifier = _table_key((tree.table or "").lower())
return tree.name.lower() if qualifier == table_key else None


def _entry_description(entry: Dict[str, Any]) -> Optional[str]:
# v1.1 uses `comment`; older YAML uses `description`.
raw = entry.get("comment") or entry.get("description")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ class UnityCatalogReport(SQLSourceReport, SemanticModelEmissionReport):
num_metric_view_unknown_join_cardinality: int = 0
num_metric_view_datasets_without_upstreams: int = 0
num_metric_view_lineage_redirected: int = 0
# Columns a measure reads that no dimension or join key of its logical
# dataset exposes, so the metric has no column edge for them.
num_metric_view_measure_columns_without_field: int = 0

# Platform resource repository for automatic cache statistics via SupportsAsObj
tag_urn_resolver_cache: Optional["UnityCatalogPlatformResourceRepository"] = None
Original file line number Diff line number Diff line change
Expand Up @@ -1004,7 +1004,8 @@
{
"destinationUrn": "urn:li:dataset:(urn:li:dataPlatform:databricks,metric_catalog.analytics.revenue_metrics.source,PROD)"
}
]
],
"fieldUpstreams": []
}
},
"systemMetadata": {
Expand Down Expand Up @@ -1142,7 +1143,8 @@
{
"destinationUrn": "urn:li:dataset:(urn:li:dataPlatform:databricks,metric_catalog.analytics.revenue_metrics.source,PROD)"
}
]
],
"fieldUpstreams": []
}
},
"systemMetadata": {
Expand Down Expand Up @@ -1283,7 +1285,8 @@
"aspectName": "metricUpstreams",
"aspect": {
"json": {
"datasetUpstreams": []
"datasetUpstreams": [],
"fieldUpstreams": []
}
},
"systemMetadata": {
Expand Down Expand Up @@ -1421,7 +1424,8 @@
{
"destinationUrn": "urn:li:dataset:(urn:li:dataPlatform:databricks,metric_catalog.analytics.revenue_metrics.source,PROD)"
}
]
],
"fieldUpstreams": []
}
},
"systemMetadata": {
Expand Down
Loading