File tree Expand file tree Collapse file tree 6 files changed +78
-0
lines changed
include/snowflake/macros/relations/dynamic_table
functional/relation_tests/dynamic_table_tests Expand file tree Collapse file tree 6 files changed +78
-0
lines changed Original file line number Diff line number Diff line change 1+ kind : Fixes
2+ body : Rename DT temp tables to avoid problematic drops
3+ time : 2025-07-16T09:55:18.719362-07:00
4+ custom :
5+ Author : colin-rogers-dbt
6+ Issue : " 713"
Original file line number Diff line number Diff line change @@ -42,6 +42,7 @@ class SnowflakeRelation(BaseRelation):
4242 {
4343 SnowflakeRelationType .Table , # type: ignore
4444 SnowflakeRelationType .View , # type: ignore
45+ SnowflakeRelationType .DynamicTable , # type: ignore
4546 }
4647 )
4748 )
@@ -60,6 +61,10 @@ class SnowflakeRelation(BaseRelation):
6061 def is_dynamic_table (self ) -> bool :
6162 return self .type == SnowflakeRelationType .DynamicTable
6263
64+ @property
65+ def is_materialized_view (self ) -> bool :
66+ return self .type == SnowflakeRelationType .DynamicTable
67+
6368 @property
6469 def is_iceberg_format (self ) -> bool :
6570 return self .table_format == constants .ICEBERG_TABLE_FORMAT
Original file line number Diff line number Diff line change 1+ {%- macro snowflake__get_rename_materialized_view_sql(relation, new_name) - %}
2+ /*
3+ Rename or move a dynamic table to the new name.
4+
5+ Args:
6+ relation: SnowflakeRelation - dynamic table relation to be renamed
7+ new_name: Union[str, SnowflakeRelation] - new name for `relation`
8+ if providing a string, the default database/schema will be used if that string is just an identifier
9+ if providing a SnowflakeRelation, `render` will be used to produce a fully qualified name
10+ Returns: templated string
11+ */
12+ alter dynamic table {{ relation }} rename to {{ new_name }}
13+ {%- endmacro - %}
Original file line number Diff line number Diff line change 110110) }}
111111select * from {{ ref('my_seed') }}
112112"""
113+
114+ DYNAMIC_TABLE_CUSTOM_SCHEMA = """
115+ {{ config(
116+ materialized='dynamic_table',
117+ snowflake_warehouse='DBT_TESTING',
118+ target_lag='30 minutes',
119+ schema='custom_schema'
120+ ) }}
121+ select * from {{ ref('simple_model') }}
122+ """
123+
124+ DYNAMIC_TABLE_CUSTOM_DB_SCHEMA = """
125+ {{ config(
126+ materialized='dynamic_table',
127+ snowflake_warehouse='DBT_TESTING',
128+ target_lag='30 minutes',
129+ schema='custom_schema'
130+ ) }}
131+ select * from {{ ref('simple_model') }}
132+ """
133+
134+ SIMPLE_MODEL = """
135+ {{ config(
136+ materialized='table'
137+ ) }}
138+ SELECT 1 as id
139+ """
Original file line number Diff line number Diff line change 1+ import pytest
2+
3+ from dbt .tests .util import run_dbt , run_dbt_and_capture
4+
5+ from tests .functional .relation_tests .dynamic_table_tests import models
6+ from tests .functional .utils import query_relation_type
7+
8+
9+ class TestDynamicTableFullRefreshCustomSchema :
10+
11+ @pytest .fixture (scope = "class" , autouse = True )
12+ def models (self ):
13+ return {
14+ "simple_model.sql" : models .SIMPLE_MODEL ,
15+ "custom_schema_dynamic_table.sql" : models .DYNAMIC_TABLE_CUSTOM_SCHEMA ,
16+ }
17+
18+ def test_dynamic_table_full_refresh_with_custom_schema (self , project ):
19+ """Test that dynamic table full refresh works with custom schema configuration."""
20+ # Initial run to create the dynamic table
21+ run_dbt (["seed" ])
22+ run_dbt (["run" ])
23+
24+ # Run full refresh - this was failing before the fix
25+ run_dbt (["run" , "--full-refresh" ])
26+ run_dbt (["run" , "--full-refresh" ])
Original file line number Diff line number Diff line change @@ -13,5 +13,6 @@ def test_renameable_relation():
1313 {
1414 SnowflakeRelationType .Table ,
1515 SnowflakeRelationType .View ,
16+ SnowflakeRelationType .DynamicTable ,
1617 }
1718 )
You can’t perform that action at this time.
0 commit comments