BI-9790: extend mcr_source_or_ref to resolve cross-schema parents on improvado_models_staging#60
Merged
Solovechik merged 2 commits intomasterfrom Apr 3, 2026
Conversation
…improvado_models_staging When target schema is improvado_models_staging, check internal_analytics_dbt_staging_* schemas for the parent table and use its fully-qualified name if found, before falling back to ref() or source(). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
oleggur
approved these changes
Apr 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
target.schema == 'improvado_models_staging', the macro now queriessystem.tablesto check if the parent model exists in anyinternal_analytics_dbt_staging_*schema and uses its fully-qualified name if foundref()if parent is in the same schema, thensource()as a final fallbackContext
On staging,
internal_analytics_srcandinternal_analyticsmodels are built ininternal_analytics_dbt_staging_*schemas. When a child model runs onimprovado_models_staging, it needs to reference these parents by fully-qualified name since they live in a different schema.A raw string is used because
ref()andsource()cannot point to arbitrary runtime schemas. This is acceptable since this code path is staging-only.Replicated merge tree tables land in
improvado_staging, but that schema is always a leaf — no models depend on it — so falling back tosource()for those is correct.Test plan
improvado_models_stagingwhose parent was built ininternal_analytics_dbt_staging_*— verify it resolves to the fully-qualified nameimprovado_models_stagingwhose parent is in the same schema — verifyref()is usedimprovado_models_stagingwith no parent in either schema — verifysource()is usedsource()is always used🤖 Generated with Claude Code