-
Notifications
You must be signed in to change notification settings - Fork 349
feat(snowflake): add transient tmp relation type for incremental models #1894
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
9c4c903
feat(snowflake): add transient tmp relation type for incremental models
b-per 94e0828
fix: use proper dispatch wrapper for resolve_incremental_tmp_relation
b-per e4486cb
fix: check language before Iceberg in dbt_snowflake_get_tmp_relation_…
b-per 19d045b
fix(snowflake): revert CLD tmp relation to table (not transient)
b-per 9ac58c1
fix(snowflake): add Transient to SnowflakeRelationType enum
b-per 2c20032
fix(snowflake): address code review feedback on transient tmp relation
b-per e74ae64
fix(snowflake): address second round of code review feedback
b-per 12320ac
test(snowflake): assert transient DDL is emitted in incremental tests
b-per 569e000
fix(snowflake): restore CLD tmp relation creation path for incrementa…
b-per d074e17
Merge branch 'main' into feat/snowflake-transient-tmp-relation
colin-k-rogers File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
dbt-snowflake/.changes/unreleased/Features-20260424-transient-tmp-relation.yaml
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| kind: Features | ||
| body: Add `tmp_relation_type=transient` support for incremental models, enabling Snowflake lineage tracking; add `snowflake__resolve_incremental_tmp_relation` dispatch macro for controlling tmp relation destination | ||
| time: 2026-04-24T00:00:00.000000-00:00 | ||
| custom: | ||
| Author: b-per | ||
| Issue: "1893" |
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
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
78 changes: 78 additions & 0 deletions
78
dbt-snowflake/tests/functional/adapter/incremental/test_incremental_transient.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| import pytest | ||
| from dbt.tests.util import run_dbt, run_dbt_and_capture | ||
|
|
||
|
|
||
| _MODEL_TRANSIENT_TMP = """ | ||
| {{ config( | ||
| materialized='incremental', | ||
| unique_key='id', | ||
| tmp_relation_type='transient', | ||
| ) }} | ||
|
|
||
| select 1 as id, 'alice' as name | ||
| {% if is_incremental() %} | ||
| union all | ||
| select 2 as id, 'bob' as name | ||
| {% endif %} | ||
| """ | ||
|
|
||
| _MODEL_TRANSIENT_TMP_DELETE_INSERT = """ | ||
| {{ config( | ||
| materialized='incremental', | ||
| incremental_strategy='delete+insert', | ||
| unique_key='id', | ||
| tmp_relation_type='transient', | ||
| ) }} | ||
|
|
||
| select 1 as id, 'alice' as name | ||
| {% if is_incremental() %} | ||
| union all | ||
| select 2 as id, 'bob' as name | ||
| {% endif %} | ||
| """ | ||
|
|
||
|
|
||
| class TestIncrementalTransientTmpRelation: | ||
| """tmp_relation_type='transient' creates a transient (not session-scoped) staging | ||
| table, enabling Snowflake lineage tracking while avoiding permanent-table | ||
| fail-safe storage costs.""" | ||
|
|
||
| @pytest.fixture(scope="class") | ||
| def models(self): | ||
| return {"transient_incremental.sql": _MODEL_TRANSIENT_TMP} | ||
|
|
||
| def test_incremental_transient(self, project): | ||
| run_dbt(["run"]) | ||
| result = project.run_sql( | ||
| "select count(*) as cnt from {database}.{schema}.transient_incremental", | ||
| fetch="one", | ||
| ) | ||
|
b-per marked this conversation as resolved.
|
||
| assert result[0] == 1 | ||
|
|
||
| _, logs = run_dbt_and_capture(["--debug", "run"]) | ||
| assert "create or replace transient table" in logs.lower() | ||
|
|
||
| result = project.run_sql( | ||
| "select count(*) as cnt from {database}.{schema}.transient_incremental", | ||
| fetch="one", | ||
| ) | ||
| assert result[0] == 2 | ||
|
|
||
| run_dbt(["test"]) | ||
|
|
||
|
|
||
| class TestIncrementalTransientTmpRelationDeleteInsert: | ||
| """transient tmp_relation_type is allowed for delete+insert strategy since | ||
| transient tables are stable across multiple statements, unlike views.""" | ||
|
|
||
| @pytest.fixture(scope="class") | ||
| def models(self): | ||
| return {"transient_delete_insert.sql": _MODEL_TRANSIENT_TMP_DELETE_INSERT} | ||
|
|
||
| def test_incremental_transient_delete_insert_runs(self, project): | ||
| run_dbt(["run"]) | ||
|
|
||
| _, logs = run_dbt_and_capture(["--debug", "run"]) | ||
| assert "create or replace transient table" in logs.lower() | ||
|
|
||
| run_dbt(["test"]) | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.