Repository navigation
feat(ingest/dbt,cube): column-level lineage for metrics - #21768
sgomezvillamor wants to merge 73 commits into
Conversation
…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>
Metrics now point at the measure columns they aggregate on their semantic model datasets (metricUpstreams.fieldUpstreams), on top of the existing dataset-level upstreams. - A create_metric measure reads its own column. - A top-level metric reads the column of each measure it resolves, including both sides of a ratio built over measures. - A declared measure that resolves to no annotated measure column is left out and counted in num_metric_upstream_fields_unresolved, so no edge points at a column the dataset does not have. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Each metric emitted for a view measure now points at that measure's column on its logical dataset (metricUpstreams.fieldUpstreams), the `alias.member` its expression aggregates. A measure missing from the logical schema is left out and counted in metric_upstream_fields_unresolved. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Connector Tests ResultsConnector tests failed for commit To skip connector tests, add the Autogenerated by the connector-tests CI pipeline. |
…h missing measure once dbt fills a derived or ratio metric's input_measures with the measures of the metrics it builds on, so those metrics do get column lineage to the measure columns. Correct the docs and the unit test, which used a manifest dbt never produces. Also visit each measure name once, so a measure listed both in input_measures and as a ratio side is not counted twice when it cannot be resolved. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The logical dataset's schema is built from the same cube members the metric loop walks, so a metric's member is always a field of it. Remove the guard and the report counter that could never be non-zero. 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>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…at-dbt-cube-metric-column-lineage # Conflicts: # docs/api/tutorials/semantic-models.md
- remove_upstream_metric no longer creates an empty upstreamMetrics snapshot when none is set, and drops duplicate edges - browse_path accepts tuples and rejects a bare string - field-level structured properties carry created/lastModified stamps - Metric upstream_fields accepts a single field or a sequence - Dashboard.remove_input_dataset uses the dataset-URN parser - get_lineage declares the response fields it indexes as required - clarify lineage docs and example comments Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Dashboard.set_charts, Dashboard.set_dashboards, DataJob.set_inlets, DataJob.set_outlets and DataJob.set_fine_grained_lineages appended to the existing list. They now replace it, matching the SDK convention and Dashboard.set_input_datasets: inputs are parsed before the aspect is touched, duplicates are dropped keeping order, and dashboard edges for URNs that stay keep their created/properties. DataJob gains add_inlet, add_outlet, remove_inlet, remove_outlet and add_fine_grained_lineage so callers have a way to add one item. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Keep parent_container exactly as on master; only the new browse_path accepts a bare string or tuple, normalized to a list. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Popping while enumerating skipped the element after each removal, so an adjacent duplicate could survive a remove_* call. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…dels # Conflicts: # docs/how/breaking-changes.md # metadata-ingestion/src/datahub/sdk/metric.py
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ent and related metrics A Metric built to update metadata only (description, owners) used to write empty metricRelationships and metricUpstreams, wiping the metric's lineage in DataHub. Lineage arguments now follow the SDK convention: None leaves DataHub's value alone, a list (including []) replaces it. When metricRelationships is not set, the metric sends an empty generic patch so the aspect still exists for hasParentMetric=false lookups, without changing an existing one. A CREATE writes the default aspect. Also adds parent_metric and related_metrics with set/add/remove methods. Cube and dbt simple metrics pass derived_from=[] to keep clearing stale metric-to-metric edges. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…mn-lineage # Conflicts: # metadata-ingestion/src/datahub/ingestion/source/cube/cube_semantic_model.py # metadata-ingestion/src/datahub/ingestion/source/dbt/dbt_semantic_model.py
- add_derived_from parses its input before creating metricRelationships, so a rejected input no longer leaves an empty aspect that wipes DataHub's. - Move the metricRelationships no-op patch to an Entity._extra_mcps hook instead of widening Metric.as_mcps; as_workunits and the entity client send it. - set_parent_metric raises SdkUsageError for a self-reference. - Document that upstream_fields alone replaces the upstream datasets. - Fix the lineage client stamp comment and the breaking-changes heading. - Test rejected input, relationship setters on hydrated metrics, and remove_related_metric without an aspect. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…at-dbt-cube-metric-column-lineage
- metric_create example: use related_metrics instead of a reversed parent_metric. - semantic_model_create example: emit as_workunits so the metricRelationships patch is included. - breaking-changes: upstream_fields alone still replaces the upstream datasets. - set_datasets: soft-delete hides the dataset from the whole catalog. - Name _extra_mcps, not as_mcps, as the source of the relationships patch. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…at-dbt-cube-metric-column-lineage
…c-column-lineage # Conflicts: # metadata-ingestion/src/datahub/ingestion/source/cube/cube_semantic_model.py # metadata-ingestion/src/datahub/ingestion/source/dbt/dbt_semantic_model.py
…c-column-lineage # Conflicts: # metadata-ingestion/tests/unit/cube/test_cube_semantic_model.py
PR SummaryOverview Cube ( dbt ( Connector docs and integration/unit tests plus golden Reviewed by Cursor Bugbot for commit 131f03d. Bugbot is set up for automated code reviews on this repo. Configure here. |
There was a problem hiding this comment.
1 issue found across 11 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="metadata-ingestion/src/datahub/ingestion/source/dbt/dbt_semantic_model.py">
<violation number="1" location="metadata-ingestion/src/datahub/ingestion/source/dbt/dbt_semantic_model.py:1073">
P2: Derived metrics are given direct column lineage from their transitive `input_measures`. Restrict measure-column resolution to metric types that directly aggregate measures; derived metrics should retain only their `derivedFrom` edges.</violation>
</file>
Reply with feedback, questions, or to request a fix.
View guided diff | Turn on auto-fix | Re-trigger cubic
| ] | ||
| measure_names.extend(resolved.measure_names) | ||
| declared_folded = {name.casefold() for name in declared_measure_names} | ||
| measure_names = [*declared_measure_names, *resolved.measure_names] |
There was a problem hiding this comment.
P2: Derived metrics are given direct column lineage from their transitive input_measures. Restrict measure-column resolution to metric types that directly aggregate measures; derived metrics should retain only their derivedFrom edges.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At metadata-ingestion/src/datahub/ingestion/source/dbt/dbt_semantic_model.py, line 1073:
<comment>Derived metrics are given direct column lineage from their transitive `input_measures`. Restrict measure-column resolution to metric types that directly aggregate measures; derived metrics should retain only their `derivedFrom` edges.</comment>
<file context>
@@ -1058,10 +1065,12 @@ def _metric_from_definition(
]
- measure_names.extend(resolved.measure_names)
+ declared_folded = {name.casefold() for name in declared_measure_names}
+ measure_names = [*declared_measure_names, *resolved.measure_names]
# A ratio's sides usually name other metrics, so they become derivedFrom
# edges rather than measure references - but `_ratio_side` still renders
</file context>
There was a problem hiding this comment.
Not changed: this is intentional. For a derived metric, a compiled dbt manifest lists in input_measures the measures of every metric it builds on, and those are the columns MetricFlow aggregates when it computes the metric, so the column edges describe what the metric reads. The derivedFrom edges to the metrics it builds on are kept as well. This is documented in dbt_post.md and covered by test_a_derived_metric_reads_the_columns_dbt_lists_as_its_input_measures. The human review raised the same question for the reviewer to decide, so I am leaving this thread open until that call is made.
|
Automated first-pass review (ingestion review agent, at Verdict: no blockers. 1 major, 2 minors; CI needs a rerun.
For the reviewer to decide: should derived metrics get direct column edges, or only CI: |
… lineage Metric fieldUpstreams are now written only when column lineage is enabled (dbt: include_column_lineage; Cube: include_lineage and include_column_lineage). When off, fieldUpstreams is left unset, as dataset upstreamLineage leaves fineGrainedLineages unset; metricUpstreams is upserted whole, so column edges from an earlier run are still cleared. The Cube semantic-model warning no longer says include_column_lineage is ignored, and tests cover the flag-off case for both connectors plus a dbt ratio side that names a metric. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks for the first-pass review. Addressed in 131f03d:
Still open for the reviewer: whether derived metrics should keep direct column edges or only |
There was a problem hiding this comment.
1 issue found across 7 files (changes from recent commits).
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="metadata-ingestion/docs/sources/dbt/dbt_post.md">
<violation number="1" location="metadata-ingestion/docs/sources/dbt/dbt_post.md:638">
P3: The documentation says unresolved measures are always counted, but the mapper skips resolution and leaves the counter at zero when `include_column_lineage` is disabled. Qualify the counting behavior as applying when column lineage is enabled.</violation>
</file>
Reply with feedback, questions, or to request a fix.
View guided diff | Turn on auto-fix | Re-trigger cubic
| - **One `semanticModel` per dbt project**, holding the join relationships between your semantic models. Its urn is `urn:li:semanticModel:(urn:li:dataPlatform:dbt,<project>,semantic_layer)`. | ||
| - **Semantic annotations on each semantic model's dataset.** The dataset keeps the urn, name, description, schema, subtype, tags, owners and lineage described above, and gains a link to its parent `semanticModel` plus a per-column annotation recording whether the column is a dimension or a measure, its aggregation function, and whether it is a time dimension. | ||
| - **One `metric` per measure with `create_metric: true`**, and one per top-level `metrics:` entry. Its urn is `urn:li:metric:(urn:li:dataPlatform:dbt,<project>,<metric_name>)`. Metrics carry an expression, a subtype naming dbt's metric type (`Simple`, `Ratio`, `Derived`, `Cumulative`, `Conversion`), upstream lineage to the datasets of the semantic models they read, and `derivedFrom` edges to the metrics they are built on. | ||
| - **One `metric` per measure with `create_metric: true`**, and one per top-level `metrics:` entry. Its urn is `urn:li:metric:(urn:li:dataPlatform:dbt,<project>,<metric_name>)`. Metrics carry an expression, a subtype naming dbt's metric type (`Simple`, `Ratio`, `Derived`, `Cumulative`, `Conversion`), upstream lineage to the datasets of the semantic models they read, column-level lineage to the measure columns they aggregate on those datasets (when `include_column_lineage` is enabled, the default), and `derivedFrom` edges to the metrics they are built on. A metric built on other metrics, such as a derived or ratio metric, also points at the measure columns of the metrics it builds on, as dbt lists them in the metric's input measures. A measure a metric names that cannot be matched to a measure column is left out of its column lineage and counted in the ingestion report. |
There was a problem hiding this comment.
P3: The documentation says unresolved measures are always counted, but the mapper skips resolution and leaves the counter at zero when include_column_lineage is disabled. Qualify the counting behavior as applying when column lineage is enabled.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At metadata-ingestion/docs/sources/dbt/dbt_post.md, line 638:
<comment>The documentation says unresolved measures are always counted, but the mapper skips resolution and leaves the counter at zero when `include_column_lineage` is disabled. Qualify the counting behavior as applying when column lineage is enabled.</comment>
<file context>
@@ -635,7 +635,7 @@ On top of the datasets described above, DataHub can also describe your dbt seman
- **One `semanticModel` per dbt project**, holding the join relationships between your semantic models. Its urn is `urn:li:semanticModel:(urn:li:dataPlatform:dbt,<project>,semantic_layer)`.
- **Semantic annotations on each semantic model's dataset.** The dataset keeps the urn, name, description, schema, subtype, tags, owners and lineage described above, and gains a link to its parent `semanticModel` plus a per-column annotation recording whether the column is a dimension or a measure, its aggregation function, and whether it is a time dimension.
-- **One `metric` per measure with `create_metric: true`**, and one per top-level `metrics:` entry. Its urn is `urn:li:metric:(urn:li:dataPlatform:dbt,<project>,<metric_name>)`. Metrics carry an expression, a subtype naming dbt's metric type (`Simple`, `Ratio`, `Derived`, `Cumulative`, `Conversion`), upstream lineage to the datasets of the semantic models they read, column-level lineage to the measure columns they aggregate on those datasets, and `derivedFrom` edges to the metrics they are built on. A metric built on other metrics, such as a derived or ratio metric, also points at the measure columns of the metrics it builds on, as dbt lists them in the metric's input measures. A measure a metric names that cannot be matched to a measure column is left out of its column lineage and counted in the ingestion report.
+- **One `metric` per measure with `create_metric: true`**, and one per top-level `metrics:` entry. Its urn is `urn:li:metric:(urn:li:dataPlatform:dbt,<project>,<metric_name>)`. Metrics carry an expression, a subtype naming dbt's metric type (`Simple`, `Ratio`, `Derived`, `Cumulative`, `Conversion`), upstream lineage to the datasets of the semantic models they read, column-level lineage to the measure columns they aggregate on those datasets (when `include_column_lineage` is enabled, the default), and `derivedFrom` edges to the metrics they are built on. A metric built on other metrics, such as a derived or ratio metric, also points at the measure columns of the metrics it builds on, as dbt lists them in the metric's input measures. A measure a metric names that cannot be matched to a measure column is left out of its column lineage and counted in the ingestion report.
Relationships follow MetricFlow's own join semantics: a semantic model that declares an entity as `foreign`, `unique` or `natural` joins to every semantic model that declares an entity of the **same name** as `primary`, `unique` or `natural`. When a key is declared in more than one semantic model, an edge is emitted to each - MetricFlow joins to each of them too. A reference to a key that is not in the ingested project is counted in the ingestion report rather than warned about, since that is normal when you filter part of a project.
</file context>
| - **One `metric` per measure with `create_metric: true`**, and one per top-level `metrics:` entry. Its urn is `urn:li:metric:(urn:li:dataPlatform:dbt,<project>,<metric_name>)`. Metrics carry an expression, a subtype naming dbt's metric type (`Simple`, `Ratio`, `Derived`, `Cumulative`, `Conversion`), upstream lineage to the datasets of the semantic models they read, column-level lineage to the measure columns they aggregate on those datasets (when `include_column_lineage` is enabled, the default), and `derivedFrom` edges to the metrics they are built on. A metric built on other metrics, such as a derived or ratio metric, also points at the measure columns of the metrics it builds on, as dbt lists them in the metric's input measures. A measure a metric names that cannot be matched to a measure column is left out of its column lineage and counted in the ingestion report. | |
| - **One `metric` per measure with `create_metric: true`**, and one per top-level `metrics:` entry. Its urn is `urn:li:metric:(urn:li:dataPlatform:dbt,<project>,<metric_name>)`. Metrics carry an expression, a subtype naming dbt's metric type (`Simple`, `Ratio`, `Derived`, `Cumulative`, `Conversion`), upstream lineage to the datasets of the semantic models they read, column-level lineage to the measure columns they aggregate on those datasets (when `include_column_lineage` is enabled, the default), and `derivedFrom` edges to the metrics they are built on. A metric built on other metrics, such as a derived or ratio metric, also points at the measure columns of the metrics it builds on, as dbt lists them in the metric's input measures. When column lineage is enabled, a measure a metric names that cannot be matched to a measure column is left out of its column lineage and counted in the ingestion report. |
What
dbt and Cube build metrics through the SDK
Metricbuilder but only wrote dataset-level upstreams. They now also write metric column lineage (metricUpstreams.fieldUpstreams) to the logical-dataset columns each metric aggregates. The logical-to-physical column mapping is unchanged and stays on the logical dataset'supstreamLineage.dbt
create_metric: truemeasure's metric reads its own measure column.metrics:entry reads the column of each measure it resolves, using the same per-model resolution as the dataset upstreams (_locate_measure). A ratio built over measures reads a column on each side, across semantic models where it spans them.input_measures, which a compiled manifest fills with the measures of every metric it builds on. ItsderivedFromedges to those metrics are unchanged.Cube
agg(alias.member)expression.Config-gated. Metric column lineage follows the connector's column-lineage option: dbt
include_column_lineage, Cubeinclude_lineageandinclude_column_lineage. When it is off,fieldUpstreamsis left unset (upstream_fields=None) rather than written as[], the same way datasetupstreamLineageleavesfineGrainedLineagesunset when the option is off. BecausemetricUpstreamsis upserted as a whole aspect, both choices leave the server in the same state: column edges written by an earlier run are cleared. Dataset-level metric upstreams are not affected by the option. The Cube semantic-model warning no longer saysinclude_column_lineageis ignored.No dangling edges. Field paths come from the same field set that builds the logical schema (dbt: the annotated measures, with
convert_column_urns_to_lowercaseapplied; Cube: the logical dataset's schema, built from the same members). A measure dbt declares that cannot be resolved is left out and counted innum_metric_upstream_fields_unresolvedrather than warned about per metric; a ratio side that names another metric is aderivedFromedge and is not counted. Every field edge in the regenerated goldens was checked against the emittedschemaMetadata.Goldens
Only
metricUpstreams.fieldUpstreamschanged (empty list → schemaField edges);datasetUpstreamsis unchanged. The multi-project glob and Cube goldens contain only those aspect changes, with no unrelated audit-stamp orlastObservednoise.Docs
Checklist
🤖 Generated with Claude Code
Summary by cubic
dbt and Cube metrics now carry column-level lineage to the logical-dataset columns they aggregate, on top of the existing dataset-level upstreams.
Behavior
fieldUpstreamsis written only when column lineage is enabled (dbt:include_column_lineage; Cube:include_lineageandinclude_column_lineage). With it off,fieldUpstreamsstays unset yet still clears column edges an earlier run wrote.create_metricmeasure reads its own column; a top-level metric reads the columns of each measure it resolves, both sides of a ratio included, plus the input measures dbt expands a derived metric into. Fields follow the dbt column lowercase rule.num_metric_upstream_fields_unresolved, so no edge points at a column the dataset does not carry.include_column_lineageis ignored.Written for commit 131f03d. Summary will update on new commits.