Skip to content

feat(ingest/unity,microstrategy): metric column lineage - #21776

Open
sgomezvillamor wants to merge 16 commits into
masterfrom
feat-unity-mstr-metric-column-lineage
Open

sgomezvillamor wants to merge 16 commits into
masterfrom
feat-unity-mstr-metric-column-lineage

Conversation

@sgomezvillamor

@sgomezvillamor sgomezvillamor commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

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 expr already 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 expr is 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, fieldUpstreams is 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 datasetUpstreams and fieldUpstreams. It is now counted in semantic_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: false leaves fieldUpstreams unset rather than writing []. The logical datasets do the same with fineGrainedLineages. Leaving it unset does not keep earlier column edges in DataHub: the metric still writes its dataset upstreams, and metricUpstreams is 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_lineage gate 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 with include_column_lineage: false metrics keep their dataset edges, have no fieldUpstreams and 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 read o_totalprice and o_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

sgomezvillamor and others added 8 commits December 1, 2026 18:28
…property helpers

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…semantic models

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Unity Catalog metric view measures and MicroStrategy metrics now write
metricUpstreams.fieldUpstreams to the logical-dataset fields they read.

- Unity: a measure's column refs (the same parse that picks its dataset
  upstreams) resolve to the dimension or join key field exposing that
  column. Columns with no such field are counted in
  num_metric_view_measure_columns_without_field.
- MicroStrategy: each fact or attribute a metric reads (including through
  a consolidation) points at its field on every logical table exposing it.
  Ones no table exposes are counted in
  semantic_model_metric_upstream_fields_unresolved.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added ingestion PR or Issue related to the ingestion of metadata docs Issues and Improvements to docs labels Dec 1, 2026
sgomezvillamor and others added 4 commits December 1, 2026 20:16
A measure's column lineage pointed at any field named after the column,
even a dimension that transforms another column. Measure columns now map
only to a dimension whose expression is that column, parsed with sqlglot
so quoted and qualified spellings match. Join keys keep the name fallback
so they do not overwrite a dimension of the same name.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The lineage query's Metric fragment fails GraphQL validation on servers
older than v1.7.0. Send it through schema projection so the fragment is
dropped there.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Reuse the existing edge for a metric that stays, as the other edge
setters do, so a hydrated entity keeps its stamps and properties.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A dataset URN passed to derived_from now raises InvalidUpstreamUrnError
with a hint to use upstream_datasets, and remove_derived_from matches
canonical URNs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.55556% with 2 lines in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...gestion/source/unity/metric_view_semantic_model.py 94.44% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@datahub-connector-tests

datahub-connector-tests Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Connector Tests Results

Connector tests failed for commit 7f39f16

View full test logs →

To skip connector tests, add the skip-connector-tests label (org members only).

Autogenerated by the connector-tests CI pipeline.

sgomezvillamor and others added 2 commits December 1, 2026 20:58
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…at-unity-mstr-metric-column-lineage

# Conflicts:
#	docs/api/tutorials/semantic-models.md
Base automatically changed from feat-sdk-semanticmodels to master December 3, 2026 15:36
…ric-column-lineage

Master now has the SDK changes (squash-merged), the Unity metric view
follow-ups, and MicroStrategy metric column lineage. Unity measure column
lineage is rebuilt on the new expression parser; MicroStrategy keeps
master's implementation and adds the unresolved-field counter.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sgomezvillamor
sgomezvillamor marked this pull request as ready for review December 3, 2026 18:07
@cursor

cursor Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

PR Summary

Overview
Adds metric column lineage (metricUpstreams.fieldUpstreams) when ingesting Databricks Unity Catalog metric views as Semantic Models and Metrics, gated on include_column_lineage.

Measure expressions reuse the existing sqlglot parse: logical table/column refs feed _measure_fields, which links each metric to schemaField URNs on logical datasets. A column maps only when a dimension’s expr is that bare column (parsed, not string-matched) or when it’s exposed as a join key—via a new column_fields index replacing field_exprs. Columns with no matching field get no column edge but keep dataset upstreams; they increment num_metric_view_measure_columns_without_field. With column lineage off, fieldUpstreams is omitted (not an empty list).

MicroStrategy semantic-model metrics already emitted field upstreams; this PR adds semantic_model_metric_upstream_fields_unresolved when a fact or attribute in a metric expression isn’t on any logical table.

Docs, integration golden MCes, and unit tests cover resolved vs unresolved columns, include_column_lineage: false, and expression-vs-name matching for dimensions.

Reviewed by Cursor Bugbot for commit 7f39f16. Bugbot is set up for automated code reviews on this repo. Configure here.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Want fixes drafted automatically? Bugbot Autofix can create code changes for findings. A team admin can enable Autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit f7750a7. Configure here.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 9 files

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

…neage

With include_column_lineage off, metric view measures no longer write
fieldUpstreams or count columns without a field, matching how the logical
datasets leave out their fine-grained lineage. The unresolved-column
counter now goes through the deferred report updates, so a view that fails
to serialize leaves it unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch was successfully deployed

1 active deployment
Preview — 7f39f16b Deployed Dec 4, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Issues and Improvements to docs ingestion PR or Issue related to the ingestion of metadata

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant