Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
@@ -1,9 +1,11 @@
# dbt's catalogMapping maps a manifest database to the database it is ingested under

- **Status:** Accepted
- **Revisions:** v1 2026-10-14 (initial); v2 2026-10-16 (query lineage)
- **Revisions:** v1 2026-10-14 (initial); v2 2026-10-16 (query lineage); v3 2026-11-26 (query lineage searches the upstreams' services)
- **Deciders:** Ingestion maintainers
- **Guard:** `TestCatalogMapping` in `ingestion/tests/unit/test_dbt.py`
- **Guard:** `TestCatalogMapping` in `ingestion/tests/unit/test_dbt.py`;
`test_dbt_query_lineage_links_the_columns_of_a_wildcard_source_in_another_service` in
`ingestion/tests/unit/entity_resolution/test_resolver.py`
- **Related:** issue #34633; PR #35020 (earlier, inference-based approach)

## Context
Expand Down Expand Up @@ -47,3 +49,18 @@ release and is dropped by dbt on any node that declares its own `openmetadata` b
on schema and table name alone, which attaches dbt metadata to an unrelated table whenever the real
one is not ingested and a namesake exists in another database. Revisit if an engine is found whose
catalog spans several OpenMetadata databases; the mapping would then need a schema-level key.

## Amendment

v3 (2026-11-26): swapping the catalog for its database is not enough when that database belongs to
another service, because the lineage parser looked tables up only in the service of the model being
processed. Query lineage now searches the model's own service first, then the service of each of its
upstreams, read from the FQN the upstream was recorded under. A wildcard upstream (BigQuery
`events_*`) keeps the configured service's FQN, so the services of the tables its expansion found
are added after it. Those are the services where `catalogMapping` and `searchAcrossDatabases` found
the parents, so column lineage follows table lineage without searching every service. The list
applies to every table the SQL reads, so one that is not a dbt upstream and misses in the model's
service is also looked up in the upstreams' services; the first service with a match wins, and a
service no upstream was found in is never searched. The model itself is not looked up there: the
parser's target is bound to the table the model was already resolved to, so a table of the same name
in an upstream's service never receives its column lineage.
Original file line number Diff line number Diff line change
Expand Up @@ -1634,6 +1634,24 @@ def create_dbt_lineage(self, data_model_link: DataModelLink) -> Iterable[Either[
)
)

def _query_lineage_services(self, model_service: str, data_model_link: DataModelLink) -> list[str]:
"""
The services the SQL's tables are looked up in: the model's own, then each one an upstream was
found in. catalogMapping and searchAcrossDatabases can resolve an upstream under another service,
and a wildcard upstream keeps the configured service's FQN while its tables can be elsewhere.
See ADR:2026-10-14-dbt-catalog-mapping-resolves-engine-database-names.
"""
wildcard_upstreams = set(self._wildcard_upstreams(data_model_link))
services = [model_service]
for upstream in data_model_link.datamodel.upstream or []:
services.append(fqn.split(upstream)[0])
if upstream in wildcard_upstreams:
services.extend(
fqn.split(model_str(table.fullyQualifiedName))[0]
for table in self._wildcard_upstream_tables(upstream) or ()
)
return list(dict.fromkeys(services))

def create_dbt_query_lineage(self, data_model_link: DataModelLink) -> Iterable[Either[LineageRequest]]:
"""
Method to process DBT lineage from queries
Expand Down Expand Up @@ -1662,12 +1680,13 @@ def create_dbt_query_lineage(self, data_model_link: DataModelLink) -> Iterable[E
lineages = get_lineage_by_query(
self.metadata,
query=query,
service_names=source_elements[0],
service_names=self._query_lineage_services(source_elements[0], data_model_link),
database_name=source_elements[1],
schema_name=source_elements[2],
dialect=dialect,
timeout_seconds=self.source_config.parsingTimeoutLimit,
lineage_source=LineageSource.DbtLineage,
view_entity=to_entity,
)
override_lineage = self._overrides_lineage(data_model_link)
for lineage in lineages or []:
Expand Down
84 changes: 81 additions & 3 deletions ingestion/tests/unit/entity_resolution/test_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@

import gc
import json
import re
import weakref
from concurrent.futures import ThreadPoolExecutor
from dataclasses import replace
from fnmatch import fnmatchcase
from threading import Barrier
from types import SimpleNamespace
from unittest.mock import MagicMock
Expand Down Expand Up @@ -733,10 +735,10 @@ def test_wildcard_sql_lineage_does_not_invent_missing_destination_columns(wildca
] == [(f"{result.right.from_entity_fqn}.id", "my_service.my_db.my_schema.output.id")]


def add_bigquery_service(transport):
transport.entities["my_service"] = DatabaseService(
def add_bigquery_service(transport, name="my_service"):
transport.entities[name] = DatabaseService(
id=uuid4(),
name="my_service",
name=name,
serviceType="BigQuery",
connection={"config": {"type": "BigQuery", "credentials": {"gcpConfig": {}}}},
)
Expand Down Expand Up @@ -1219,6 +1221,82 @@ def test_dbt_wildcard_source_follows_the_catalog_mapping(sdk, monkeypatch, servi
assert dbt_lineage_sources(source, manifest_entities, model) == {daily.id.root}


def answer_scoped_search(transport, monkeypatch, *tables):
"""A table search by FQN pattern, which the fake transport otherwise answers alike for every pattern."""
search = transport.get

def get(path):
url = urlsplit(path)
params = parse_qs(url.query)
if url.path != "/search/fieldQuery" or params.get("index") != ["table_search_index"]:
return search(path)
pattern = re.sub(r"\\(.)", r"[\1]", params["fieldValue"][0].replace('"', ""))
names = [item.fullyQualifiedName.root for item in tables if fnmatchcase(item.fullyQualifiedName.root, pattern)]
return {
"hits": {
"hits": [{"_source": {"fullyQualifiedName": name}} for name in names],
"total": {"value": len(names), "relation": "eq"},
}
}

monkeypatch.setattr(transport, "get", get)


@pytest.mark.parametrize(
("catalog_mapping", "search_across_databases"),
[({"my_db": "my_db"}, False), (None, True)],
ids=["catalogMapping", "searchAcrossDatabases"],
)
def test_dbt_query_lineage_links_the_columns_of_a_wildcard_source_in_another_service(
sdk, monkeypatch, catalog_mapping, search_across_databases
):
# The wildcard upstream keeps the configured service's FQN while its tables are found under another one
metadata, transport = sdk
add_bigquery_service(transport)
add_bigquery_service(transport, "other_service")
daily = bigquery_family_in("other_service", "my_db")
summary = table("my_service.my_db.my_schema.summary")
for entity in (daily, summary):
entity.columns = [
Column(name=name, dataType="INT", fullyQualifiedName=f"{entity.fullyQualifiedName.root}.{name}")
for name in ("id", "label")
]
transport.entities[entity.fullyQualifiedName.root] = entity
answer_unscoped_search(transport, monkeypatch, daily)
answer_scoped_search(transport, monkeypatch, daily, summary)
source, manifest_entities, model = wildcard_source_dbt(metadata)
source.source_config.catalogMapping = catalog_mapping
source.source_config.searchAcrossDatabases = search_across_databases
source.source_config.parsingTimeoutLimit = 10
source.config.serviceConnection = SimpleNamespace(
root=SimpleNamespace(config=SimpleNamespace(type=SimpleNamespace(value="BigQuery")))
)
upstream = source.parse_upstream_nodes_with_names(manifest_entities, model, expand_wildcard_sources=True)
link = DataModelLink(
table_entity=summary,
upstream_table_ids={node.fqn: node.table_id for node in upstream if node.table_id},
datamodel=DataModel(
modelType="DBT",
upstream=[node.fqn for node in upstream],
sql="select id, label from `my_db`.`my_schema`.`events_*`",
),
)
assert {edge.right.lineage_request.edge.fromEntity.id.root for edge in source.create_dbt_lineage(link)} == {
daily.id.root
}

requests = [outcome.right.lineage_request for outcome in source.create_dbt_query_lineage(link) if outcome.right]

assert {
(column.fromColumns[0].root, column.toColumn.root)
for request in requests
for column in request.lineage_details.columnsLineage or []
} == {
(f"{daily.fullyQualifiedName.root}.{name}", f"{summary.fullyQualifiedName.root}.{name}")
for name in ("id", "label")
}


def test_dbt_wildcard_source_falls_back_to_the_manifest_database(sdk):
metadata, transport = sdk
add_bigquery_service(transport)
Expand Down
Loading
Loading