Repository navigation
Fixes 38288: Reuse dbt tables already found during the run - #38291
akashverma0786 merged 4 commits into
Conversation
…e them. A table is looked up as its own model and again for every model and test that depends on it. Keep each table found in the run and reuse it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
add_dbt_sources looked the source table up itself, and the source's own lookup right after it did the same search again. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A smaller cap loses most of the saving: dbt tests come after the last model in the manifest, so their parents would be evicted by then. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
❌ 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 |
# Conflicts: # ingestion/tests/unit/test_dbt.py
Code Review ✅ Approved 🟡 Medium risk 1 closed / 1 findingsCaching resolved dbt tables changes lookup reuse across models and freshness results; incorrectly keyed entries could affect lineage associations. Reuses dbt tables already found during a run by caching lookups in a bounded ✅ 1 closed✅ Quality: resolved_tables is an unbounded dict cache of full Table entities
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 #38288
The dbt connector looked a table up as its own model, and again for every model, test, and source freshness result that names it. Nothing kept the table found the first time.
_resolve_tablebuilds the FQN, looks the table up, and keeps what it finds in anLRUCacheofLRU_CACHE_SIZE(4096) entries. The cache is keyed by the database, schema, and name the manifest uses, plus whether the name is literal. The model loop, upstream parsing (which dbt tests also go through), andadd_dbt_sourcesall use it. The cache is reset per project inyield_data_models, likereported_unresolved_upstreams.The cap has to hold a whole project to keep the saving: every dbt test comes after the last model in the manifest, so with a small cap the tests find their parents evicted. On the manifest below, with the search stubbed, 1000 entries made 16,139 searches and 2000 made 11,271; 3000 and 4096 both made 7,670. The cached tables are the same objects the data-model links keep for the whole run, so the cache adds no table data of its own.
Tables that are not found are not kept, so they are still looked up again.
_get_table_entityreturnsNonefor a failed search as well as for a missing table. KeepingNonewould turn one transient search error into a missing table for the rest of the run.On our production manifest (2,862 models, seeds, snapshots, and sources; run results for 5,256 tests),
yield_data_modelswithes_search_from_fqnstubbed made 40,364 searches before this change and 7,670 after, for the same 2,844 distinct tables. The parsed data-model links, their upstreams, and the tests' upstreams were identical before and after.The stub bypasses
_search_es_entity, which is alreadylru_cache(maxsize=512), so it overstates what reaches the server. In the production run on 2.0.8, parsing sent 14,529GET /api/v1/search/fieldQueryand 14,391GET /api/v1/tables/name/...(from the server access log, about 9.5 minutes of server time). With this change parsing makes at most 7,670 searches, and at least one per distinct table (2,844), before that cache removes any repeats.That cache does not cover this case for two reasons. It keys each search separately, and resolving one model makes two different searches (
_build_table_fqn, then_get_table_entitywithfields=sourceHash), plus the catalogMapping and searchAcrossDatabases branches. And 512 entries do not hold a project: every test comes after the last model, so by then the parents are evicted. Raising that cap would change every caller ofes_search_from_fqnin every connector; this cache is scoped to the dbt source and holds one resolved table per manifest name.Type of change:
High-level design:
N/A — small bug fix in one file. The two call sites that built an FQN and then looked the table up now share one helper, and
add_dbt_sourcesuses it too.Tests:
Use cases covered
upstream_table_idsUnit tests
ingestion/tests/unit/test_dbt.pyTestDbtLineageReusesParsedUpstream::test_a_table_used_as_model_and_upstream_is_searched_for_once: before the change,raw_orderscost 4 searches andorders2.TestDbtSourceIdentifiers::test_freshness_reuses_the_source_table_lookup: before the change, a run withsources.jsonmade 2 more searches than one without.TestAddDbtSourceFreshnessResults._sourceandTestDbtLineageReusesParsedUpstream._sourcenow setresolved_tables, since they build the source with__new__.tests/unit/test_dbt.py,test_dbt_test_definition.py,test_dbt_test_descriptions.py: 346 passed, 1 failed.TestStorageStreamingBehavior::test_gcs_passes_generator_to_groupingalso fails onmainin my venv, becausegoogle-cloud-storageis not installed there.metadata.pyare covered (coverage run --include='*/dbt/metadata.py' -m pytest ...).Backend integration tests
Ingestion integration tests
Playwright (UI) tests
Manual testing performed
yield_data_modelsover our production manifest and 149 run-results files withes_search_from_fqnstubbed to answer every search, counting calls: 40,364 onmain, 7,670 on this branch. The stub bypasses the 512-entry_search_es_entitycache; production numbers are above.UI screen recording:
Not applicable — ingestion-only change.
Checklist:
I have read the CONTRIBUTING document.
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.No 🔴. Two 🟡:
add_dbt_sourcesrepeated the lookup (fixed here); tables that are not found are looked up again (left, see above). Gitar asked for a bounded cache; it now usesLRUCache(LRU_CACHE_SIZE).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.Nothing to record. The cap reuses the existing
LRU_CACHE_SIZEdefault, and the rule "do not keep misses" is stated in a comment next to the code.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.
🤖 Generated with Claude Code


Confidence Score: 5/5
The PR appears safe to merge.Summary
Reuses successful dbt table lookups across models, upstream references, and source freshness checks.
Reviews (6) · Last reviewed commit: "Bound the dbt table cache with LRUCache(..." · Reviewed by Greptile