feat(ingest/unity,microstrategy): metric column lineage
SG
1h ago+268+268+012345678901234567890123456789-19-19-01234567890123456789
Builds on #21764, which added upstream_fields to the SDK Metric builder, and on #21745 (Unity metric view follow-ups). Sibling PRs do the same for dbt and Cube (#21768) and Snowflake (#21770).
What changes
Databricks Unity Catalog metric views build metrics through the SDK but only wrote dataset-level upstreams. They now also write metric column lineage (metricUpstreams.fieldUpstreams) to the logical-dataset fields each measure reads. MicroStrategy already writes metric column lineage (#21737); this PR only adds a counter for what it can't resolve. The logical-to-physical column mapping is unchanged in both.
Unity Catalog (metric views, semantic model mode)
- A measure's
expralready goes through one sqlglot pass (_parse_expression) to find the logical tables it reads. That pass now also records the logical column each reference reads, so the dataset and column upstreams come from the same parse. There is no second parser. - A column becomes a field edge when the logical dataset exposes it as a field: a dimension whose
expris just that column (quoted, qualified or not), or a join key field. Join keys use the same column-to-field index, which replaces the text match on dimension expressions. A struct field (source.address.city) is not the column itself, so it doesn't count. - A column that no dimension or join key exposes has no field to point at. It gets no column edge and is counted in
num_metric_view_measure_columns_without_field. There is no warning: the measure's dataset edge still covers the column, and nothing in the YAML is wrong. - Repeated refs (
order_date,source.order_date,ORDER_DATE) fold to one edge. - Metric column lineage follows
include_column_lineage, like the logical datasets' column lineage. When it is off, metrics keep their dataset upstreams,fieldUpstreamsis left unset and nothing is counted.
MicroStrategy (semantic model)
- A fact or attribute that a metric reads but no logical table exposes was dropped silently from both
datasetUpstreamsandfieldUpstreams. It is now counted insemantic_model_metric_upstream_fields_unresolved.
Design decisions
- Unity: resolve against existing fields, do not add new ones. A Unity logical dataset only carries dimensions and join keys, so a measure such as
SUM(o_totalprice)over a column that no dimension exposes gets no column edge. Join keys are already added as fields so that relationships have something to point at. Measure input columns could be added the same way, which would give most measures a column edge, but it would change every logical dataset's schema. This PR leaves that out (see the question below). - One counter per connector, no new warnings. In both connectors the unresolved case is a modelling choice, not something an operator can fix. The Unity counter is updated only once the view is emitted, like the connector's other metric-view report updates.
- Unity:
include_column_lineage: falseleavesfieldUpstreamsunset rather than writing[]. The logical datasets do the same withfineGrainedLineages. Leaving it unset does not keep earlier column edges in DataHub: the metric still writes its dataset upstreams, andmetricUpstreamsis written whole, so DataHub ends up with no column edges either way. - MicroStrategy: no flag. The connector has no column-lineage option. Its metric column edges point at the semantic model's own logical fields and come from the same metric model read as the metric's dataset upstreams, which are not gated either.
extract_lineage/extract_model_lineagegate the logical-to-warehouse lineage, which this PR does not touch.
Tests
- Unity (
tests/unit/unity/test_unity_metric_view_semantic_model.py): one test covers the resolved cases (a source dimension, a dimension on a joined table, a join key), three spellings of the same column folding to one edge, the unresolved case (counted, dataset edge kept), and no new warnings. Another test checks that withinclude_column_lineage: falsemetrics keep their dataset edges, have nofieldUpstreamsand count nothing. The failed-view test also checks the unresolved-column counter stays at zero. - MicroStrategy (
tests/unit/microstrategy/test_microstrategy_semantic_model.py): a fact on two tables gives a field edge on each, a repeated fact token adds nothing, an attribute gives a field edge, and a fact on no table is counted. The consolidation test also checks the attribute's field edge. - Golden: the Unity metric view golden gains
"fieldUpstreams": []on its four metrics. Its measures reado_totalpriceando_orderkey, which no dimension exposes, so they get no column edge, as expected. pytest tests/unit/unity tests/integration/unity tests/unit/microstrategy tests/integration/microstrategy tests/unit/sdk: 1650 passed, 1 xfailed.
Questions for the reviewer
- Should Unity add a measure's input columns as fields on the logical dataset, as it already does for join keys? Most real measures would then get column lineage, but every metric view's logical schema would change.
Checklist
- The PR conforms to DataHub's Contributing Guideline (particularly PR Title Format)
- Links to related issues (if applicable)
- Tests for the changes have been added/updated (if applicable)
- Docs related to the changes have been added/updated (if applicable). If a new feature has been added a Usage Guide has been added for the same.
- For any breaking change/potential downtime/deprecation/big changes an entry has been made in Breaking Changes (not a breaking change: this adds lineage edges and no config or URN changes)
🤖 Generated with Claude Code