fix(ingest/unity): metric view follow-ups to semantic model emission
Merged
SG
1d ago+3689+3689+0123456789012345678901234567890123456789-842-842-012345678901234567890123456789
Follow-ups to #21252, which emits Databricks Unity Catalog metric views as Semantic Models and Metrics.
What changes
- One parse of the YAML. A new
unity/metric_view_spec.pyparses a metric view's YAML into a typed spec. It flattens the nestedjoinstree and foldsfields:into the dimensions. TheMetric Viewdataset path and the semantic model mapper both read that spec, so they agree on joins, names and shape problems. Entries without a name, repeated field names and repeated measure names (the first definition is kept) are counted and reported instead of dropped silently. fields:is accepted. Databricks documentsfields:as the preferred key anddimensions:as its synonym. Both are read,fields:first, and a repeated name keeps its first definition.materialization.materialized_views[].dimensionsis left as written.- Field metadata kept on columns. Unity Catalog can strip a field's
comment,display_name,synonymsandformatfrom the YAML it returns and keep them on the view's columns (the column comment andtype_jsonmetadata). It keeps thefilteras themetric_view.whereproperty. These now fill whatever the YAML lacks, on both paths. Depending on the workspace, Unity Catalog may keep only the comment and drop the display name, synonyms and format, which are then not ingested. Columns whose metadata is not valid JSON are counted and reported. - Join cardinality. A join's
cardinalitysets the relationship's cardinality:many_to_one→N_ONE,one_to_many→ONE_N, absent →N_ONE(the Databricks default). Other values leave it unset and are reported. - Join keys. A join column the metric view does not declare as a field is added to its logical dataset so the relationship resolves. It is now typed
OTHERand described as a join key, not typed as a dimension, since the metric view cannot be grouped by it. A declared field that covers a join key keeps its dimension type. metric_view.*properties with semantic models on. They go on the logical datasets. View-level and measure properties go on<view>.source, and each dimension's properties go on the dataset that holds it. Both paths also getmetric_view.join.<name>.cardinality/.rely.<key>. Unity Catalog's own table properties are not copied.- The resolved mode decides the entity type. With semantic models on, a metric view is never emitted as a dataset, and with them off it is never emitted as a semantic model. A metric view that can't be ingested as a semantic model, because its YAML can't be read or mapping fails, no longer fails its schema and is no longer emitted as a dataset instead. It is skipped with one warning that carries the cause, is not counted as processed, and is counted in
num_metric_views_semantic_model_failed. The view's entities are built in full before any is emitted. The semantic model, metrics and logical datasets (fields included) from a previous run are carried forward in the checkpoint; aMetric Viewdataset from an earlier dataset-mode run is removed. Lineage from notebooks, Genie agents and tables that read the view points at the carried-forward logical datasets, or is dropped when there are none. Counters and warnings about a view's entries are reported only once its model is built. Thenum_metric_views_semantic_model_fallbackcounter is removed, since that fallback no longer exists. Carried-forward checkpoint URNs now keep their own entity type. - Unparseable join conditions are reported with their parse error. Before, they were reported as unqualified-column joins. In semantic model mode, unknown table qualifiers and measure expressions that are not valid SQL are now counted and reported too, as on the dataset path. Each expression is parsed once; columns of a subquery
sourceand struct fields of a table column are not reported as unknown tables, and a measure that does not parse readssource. - A logical dataset gets a view definition only when its
sourceis a subquery. An unresolved one-part name such asordersno longer becomes a SQL view definition. - Shared gate reporting.
resolve_and_report_emissionand aSemanticModelEmissionReportmixin incommon/semantic_model_gate.pynow record the emission decision and raise the version, kill-switch and refused-request warnings for Unity Catalog, Snowflake and dbt. Unity Catalog and Snowflake keep their warning titles. dbt's refused-request warning is now titledemit_semantic_model_entities forced off, like the other two (it was "Cannot emit dbt semanticModel/metric entities"). When the server's version can't be parsed or the Metrics check fails, emission resolves to off and the warning says so, with the cause in the decision reason. A refused recipe request adds no second warning when one of these already explains it. - Metric-view and gate warnings in the Unity Catalog source now log by default (no
log=False). A metric view YAML that can't be read gets one warning, which states the consequence for the mode: skipped in semantic model mode, emitted as aMetric Viewdataset without its YAML's properties and lineage otherwise. - Tests. A stateful test pins what happens when emission is switched on. The old
Metric Viewdataset and theDimension,MeasureandWindow Measuretags are soft-deleted, and nothing else is. - Docs. The Databricks concept mapping,
unity-catalog_post.mdand the breaking-changes entry are updated. The tag wording now says the tags are soft-deleted, and that other assets tagged with them still reference them.
Decisions
These follow the Databricks metric view YAML reference.
| Item | What the reference says | Decision |
|---|---|---|
Join cardinality | A join key. "Optional. Defaults to many_to_one." Values: many_to_one, one_to_many. | many_to_one → N_ONE, one_to_many → ONE_N, absent → N_ONE. Any other value → cardinality unset, plus a report warning. Direction: from is the parent table, to is the join. |
fields: vs dimensions: | "fields and dimensions are equivalent keywords... fields is the preferred term". dimensions "is accepted as a synonym for backward compatibility". | Accept both at the top level, merged with fields first. On a duplicate name the first definition wins, and the duplicate is reported. Only the top-level keys are touched: materialization.materialized_views[].dimensions keeps its name. |
| Measures as fields too | Measures are read with MEASURE(...). Fields are "metric view columns used in SELECT, WHERE, and GROUP BY". | No change. A measure stays a metric only, as Snowflake does with METRIC. |
metric_view.* properties with semantic models on | SemanticModelInfo and MetricInfo have no customProperties. | Put them on the logical datasets' datasetProperties.customProperties, with the same keys as the dataset path. Spec-level keys and measure keys go on the source dataset. Dimension keys go on the dataset that holds that dimension. |
| Warning logging | — | log=True (the default) for the metric-view and gate warnings touched here. |
| Migration command | — | Not needed. |
| Bad metric view | — | The resolved mode decides the type; there is no fallback. When a view's YAML can't be read or mapping fails: warn with the cause, count it, emit nothing for that view and carry its previous semantic-model URNs forward in the checkpoint. |
Implementation notes
SemanticModelDatasetdoes not acceptcustom_propertiesin its constructor, so the mapper callsset_custom_properties(...)after building the dataset. The SDK is unchanged.- No golden changed for join cardinality. The only join in the existing semantic-model golden uses unqualified columns, so it emits no relationship. A unit test covers the mapping.
Notes for reviewers
- The companion connector-tests PR, acryldata/connector-tests#990, adds real-workspace tests for metric views as semantic models. Its metric view job passes against this PR's wheel. The existing Databricks metric view goldens on connector-tests
maindo not change with this PR. tests/unit/snowflakeandtests/integration/snowflake/test_snowflake.py::test_snowflake_basicinteract when run in one process. The data-dictionary cache stats carry over between tests, andget_tables_for_databasemisses reads 34 instead of 1. This reproduces onmasterwithout this change. The test passes alone and within the Snowflake integration suite.- Possible follow-ups: Unity Catalog warnings unrelated to metric views still pass
log=False; they are left as they are here. Format, display name and synonym values that parse but cannot be used are dropped without a report; only JSON-level errors in column metadata are counted. Both are left out to keep this PR's scope. The Snowflake source emits relationships on undeclared join keys as field paths the logical dataset does not have, and warns "Semantic view join key does not match any field"; it could add those keys asOTHERfields, for example from the PRIMARY KEY metadata it already parses.
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)
- For any breaking change/potential downtime/deprecation/big changes an entry has been made in Breaking Changes
🤖 Generated with Claude Code
Summary by cubic
Hardens Unity Catalog metric view semantic model emission: the metric view YAML is parsed once into a typed spec shared by the dataset path and the semantic model mapper, and a metric view that fails to read or fails to map is skipped with a warning instead of failing the whole schema.
Bug Fixes
- Accepts the documented
fields:key as a synonym fordimensions:, keeps the first definition on a repeated name, and reports repeated measure names, absent names, and malformed YAML sections. - Fills field metadata (comment, display_name, synonyms, format) from the view's columns when Unity Catalog strips it from the returned YAML.
- Maps join cardinality to relationship cardinality, and types join keys that are not declared fields as
OTHER(join keys) instead ofDIMENSION; dimensions are resolved before join keys are added. - A view that fails to read or map is skipped: its URNs and lineage are carried forward so fields are not soft-deleted and the type does not flip, and its warning and a failure counter account for it.
- When the server version cannot be parsed or the Metrics probe fails, emission resolves to off and the warnings say so; mapping counters apply only once the model is fully built.
Refactors
metric_view.*custom properties now land on the logical datasets instead of being lost; theMetric Viewsubtype is set whenever the databricks-sdk identifies metric views.- Emission decisions and fallback warnings go through a shared gate used by Unity Catalog, Snowflake, and dbt, which now share the same "forced off" warning title; a refused request no longer adds a second warning when a fallback warning already explains it.
- Switching emission on soft-deletes only the legacy
Metric Viewdataset and theDimension,Measure, andWindow Measuretags.