Repository navigation
Fixes 38910: dbt column lineage for sources found in another database service - #38911
tseporamaisa wants to merge 5 commits into
Conversation
…were found catalogMapping and searchAcrossDatabases can resolve a model's upstream under another database service. Table lineage uses that table, but query lineage searched only the model's own service, so the model never got column lineage from it.
❌ PR checklist incompleteThis PR cannot be merged until the following are addressed on its linked issue:
The fields live on the linked issue in the Shipping project (open the issue → right sidebar → Projects). After you set them, re-run this check (or push a commit) — issue/project changes do not re-trigger it automatically. Maintainers can bypass this check by adding the |
There was a problem hiding this comment.
🟡 Changes recommended
Cross-service BigQuery wildcard upstreams omit the resolved service from lineage lookup, leaving column lineage missing despite successful table lineage.
1 open issue
What changed in this PR
Extends #35603’s catalog-mapping fix so dbt column lineage can resolve sources ingested in another database service, addressing #38910.
Changes:
- Searches the model’s service first, then deduplicated upstream services.
- Adds real-parser regression tests for cross-service resolution through
catalogMappingandsearchAcrossDatabases. - Updates the decision record with lookup precedence and scope.
Placement: The change affects dbt ingestion’s column-lineage requests. Tests were inspected but not run; persisted server results were not verified.
Trade-off: weighed by the author, holds because additional lookups are limited to upstream services and stop at the first match.
Recommendation: request changes to complete handling of supported cross-service upstreams.
| File | Description |
|---|---|
| ingestion/tests/unit/test_dbt.py | Shares test helpers and adds cross-service column-lineage regressions. |
| ingestion/src/metadata/ingestion/source/database/dbt/metadata.py | Adds upstream services to query-lineage lookup candidates. |
| docs/decisions/2026-10-14-dbt-catalog-mapping-resolves-engine-database-names.md | Documents cross-service lookup order and scope. |
Review effort: Balanced
…les were found A wildcard upstream such as BigQuery's events_* keeps the configured service's FQN, while catalogMapping or searchAcrossDatabases can find its tables under another service. Query lineage now adds the services of the tables its expansion found.
The model is the table its SQL creates, so query lineage now hands it to the parser instead of looking it up across the wider service list, where a namesake in an upstream's service could take its column lineage before search has indexed it. Tests pin that the model's own service is searched first, and TestCatalogMapping clears the lineage search caches between tests.
Code Review ✅ Approved 🟡 Medium riskExpanding dbt column-lineage searches to upstream services could associate SQL columns with a same-named table in the first matching service. Fixes dbt query lineage so column lineage is created for models whose sources live in another database service, found via VerificationRules No rules evaluated Functional validation Not enabledAuto-approval Not enabledFor more verification details, comment OptionsDisplay: compact → Showing compact verification results. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source |

Describe your changes:
Fixes #38910
I worked on dbt query lineage (the step that produces column lineage) because models whose sources are ingested under a different database service get table lineage but never column lineage when the source is found through
catalogMappingorsearchAcrossDatabases.Cause.
create_dbt_query_lineagepassesservice_names=source_elements[0], the model's own service, toget_lineage_by_query, so the parser looks up every table in the compiled SQL in that one service. Table lineage resolves the same upstream through_get_table_entity_in_mapped_database(configured service, then*) or thesearchAcrossDatabasesfallback, and records it under the FQN it was found at, e.g.events.events.mobile_app.users. The parser then searcheswarehouse.events.mobile_app.users, finds nothing, and no column lineage is created. #35603 swaps a mapped catalog for its database in the SQL, which is enough when that database is in the model's service; the service was never addressed.Fix. The parser now searches the model's own service first, then the service of each of the model's upstreams, read from
datamodel.upstream: the FQNs table lineage already resolved. A wildcard upstream (BigQueryevents_*) keeps the configured service's FQN even when its tables were found elsewhere, so the services of the tables its expansion found are added too.search_table_entitiesreturns the first service with a match, so a table that is found in the model's service resolves exactly as before; the other services are searched only when it misses. Without cross-service upstreams the list is just the model's service, so nothing changes for anyone not using these settings.The model itself is passed to the parser as the query's target (
view_entity), so it is never looked up across the wider list. Otherwise a table of the model's name in an upstream's service could take its column lineage while search hasn't indexed the model yet, and withoverrideLineagethat table's dbt edges would be deleted first. This also saves one lookup per model.I amended ADR:2026-10-14-dbt-catalog-mapping-resolves-engine-database-names (v3). Its query lineage paragraph says swapping the catalog lets column lineage find the sources, which doesn't hold when the mapped database is in another service, and the service order is a rule worth keeping in the tree.
Alternatives considered
service_names=[model service, "*"]whencatalogMappingis set. One line, and the same*fallback table lookups use. I didn't pick it because it widens the lookup for databases nobody mapped: anydb.schema.tablein the SQL that misses in the model's service would match a namesake in whatever service has one, which is whatsearchAcrossDatabasesis the opt-in for. It also needs a second condition to coversearchAcrossDatabases.The chosen approach adds no lookups of its own: wildcard expansions are reused from the run's cache, which
create_dbt_lineagefills before query lineage runs. The cost is one more search per extra upstream service for a table that misses in the model's service. Only hits are cached, so that miss is searched again for each model that reads the table. It only happens for models with upstreams in another service, and it never searches every service.Edge cases
ref()/source()) and misses in the model's service is now also looked up in the upstreams' services. I think that's right, since the model already reads from those services, and the search never goes beyond them.db.schema.tableexists under several of the services, the first in the list wins (the model's service, then upstream order), the same first-match rule as today.None) adds no service beyond its own FQN's._map_catalogs_in_sql(Fixes 34633: column lineage for dbt models whose catalog is mapped with catalogMapping #35603), so a BigQuerycatalogMappingthat renames the database still gets no column lineage. That predates this PR and is a separate change.Type of change:
High-level design:
N/A — small change.
Tests:
Use cases covered
trino_svcreads a source thatcatalogMappingresolves underbq_svc: query lineage links its columns to thebq_svctable.searchAcrossDatabasesand no mapping.events_*source whose tables are found under another service, withcatalogMappingand withsearchAcrossDatabases: its columns are linked.Unit tests
ingestion/tests/unit/test_dbt.py,ingestion/tests/unit/entity_resolution/test_resolver.pyTestCatalogMapping::test_query_lineage_links_the_columns_of_a_source_found_in_another_service, forcatalogMappingand forsearchAcrossDatabases. It runs a manifest throughyield_data_modelsand the resulting link throughcreate_dbt_query_lineagewith the real Trino lineage parser; only the search backend is faked, and it knows the source table only underbq_svc. Both cases fail onmain(no lineage at all) and pass with this change.test_dbt_query_lineage_links_the_columns_of_a_wildcard_source_in_another_service(test_resolver.py), for both settings, through the real SDK, BigQuery's table resolution and the lineage parser, with only the HTTP boundary faked. Both cases fail without the wildcard part of the change.TestCatalogMapping::test_query_lineage_looks_in_the_models_own_service_firstpins the service order (it fails if the upstreams' services go first), andtest_query_lineage_keeps_the_model_as_its_target_before_search_has_indexed_itfails withoutview_entity.TestCatalogMappingnow clears the lineage search caches around each test. Without that, the target test passed in a full run only because a previous test had cached the model's table.test_query_lineage_links_the_columns_of_the_mapped_sourcenow setsupstreamandupstream_table_idson its link, as a realDataModelLinkhas. Its table and search helpers moved to the class so the tests share them.dbt/metadata.pyas a whole from the run below. The changed lines are all covered by the new tests.tests/unit/test_dbt*.py,tests/unit/test_lineage_empty_result.py,tests/unit/lineage/,tests/unit/entity_resolution/andtests/unit/topology/database/.ruff checkandruff format --checkpass on the changed files. basedpyright reports no new finding inmetadata.py.scripts/harness/check_decision_records.pyis clean.Backend integration tests
Ingestion integration tests
tests/integration/has no dbt suite, so the unit tests above are the coverage for this connector.Playwright (UI) tests
Manual testing performed
I run 2.0.7, so I tested the same change applied to the 2.0.7.2 connector against a local 2.0.7 server holding my two Redshift services (
warehouseandevents; names changed here), with my real dbt artifacts andcatalogMapping: {events: events}:warehouse.warehouse.mobile_app.usershas the dbt edge fromevents.events.mobile_app.userswith 0 column links.create_dbt_query_lineagedoes:service_names=["warehouse"](current) gives no lineage;["warehouse", "events"](what this change passes) gives 1 edgeevents.events.mobile_app.users → warehouse.warehouse.mobile_app.userswith 7 column links.UI screen recording:
Not applicable — ingestion-only bug fix with no UI change.
Checklist:
I have read CONTRIBUTING.md (the pre-review gate) and the contributor docs.
My PR title is
Fixes <issue-number>: <short explanation>My PR is linked to a GitHub issue via
Fixes #<issue-number>above.I have commented on my code, particularly in hard-to-understand areas.
For JSON Schema changes: I updated the migration scripts or explained why it is not needed.
For a UI feature or feature task: as part of PR creation, I ran the PR build in Docker with sample data and embedded a verified GitHub-hosted recording plus build/health evidence above (or explained why this requirement is not applicable).
I have added tests (unit / integration / Playwright as applicable) and listed them above.
Self-review: I reviewed the final diff against
REVIEW.md(thepr-checklistskill runs it) and fixed every 🔴 finding, or answered it on the line below.Reviewed at
58d33a2591. Fixed: the first pass flagged the ADR amendment for saying non-upstream tables stay in the model's service, which the code doesn't keep; I corrected the text. After Copilot's wildcard finding, the next pass's nits were also fixed: the target is bound to the model (view_entity), the service order is pinned by a test, and the ADR Guard line names the new test. No 🔴 open. Placement: dbt runs whose upstreams (or wildcard tables) are found under another service throughcatalogMappingorsearchAcrossDatabases; only the column lineage edges they send change. dbt Cloud's_yield_column_lineagehas the same single-service lookup; that predates this PR and is left for a follow-up. Trade-off: weighed, holds because the search is bounded to the model's service and the services its upstreams were found in. Recommendation: approve.Decision check: if this PR decides something the next contributor could undo — a schema field, REST path or format another component or repo must agree with, a new default or limit, an ordering that must hold, or a rule stated only in this description — it adds a record under
docs/decisions/(see itsREADME.md). This description is gone fromgit logafter the squash-merge.I have added a test that covers the exact scenario we are fixing. For complex issues, comment the issue number in the test for future reference.
Questions for maintainers
[2.0]backport be welcome? I'm happy to open one.