From a0739879d09c0cd7e897806191c2c5115070e9b8 Mon Sep 17 00:00:00 2001 From: Mila Page <67295367+versusfacit@users.noreply.github.com> Date: Thu, 21 Mar 2024 10:43:41 -0400 Subject: [PATCH] repoint dev deps to main --- .../Under the Hood-20240227-010428.yaml | 6 ++++++ dbt/adapters/snowflake/relation.py | 21 ++++++++++++++++++- .../macros/relations/dynamic_table/create.sql | 10 +++++++++ tests/unit/test_renamed_relations.py | 17 +++++++++++++++ 4 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 .changes/unreleased/Under the Hood-20240227-010428.yaml create mode 100644 dbt/include/snowflake/macros/relations/dynamic_table/create.sql create mode 100644 tests/unit/test_renamed_relations.py diff --git a/.changes/unreleased/Under the Hood-20240227-010428.yaml b/.changes/unreleased/Under the Hood-20240227-010428.yaml new file mode 100644 index 000000000..5252d0313 --- /dev/null +++ b/.changes/unreleased/Under the Hood-20240227-010428.yaml @@ -0,0 +1,6 @@ +kind: Under the Hood +body: Add unit test for transaction semantics. +time: 2024-02-27T01:04:28.713433-08:00 +custom: + Author: versusfacit + Issue: "912" diff --git a/dbt/adapters/snowflake/relation.py b/dbt/adapters/snowflake/relation.py index 9139362a4..8c93de69b 100644 --- a/dbt/adapters/snowflake/relation.py +++ b/dbt/adapters/snowflake/relation.py @@ -1,5 +1,5 @@ from dataclasses import dataclass, field -from typing import Optional, Type +from typing import FrozenSet, Optional, Type from dbt.adapters.base.relation import BaseRelation from dbt.adapters.relation_configs import RelationConfigChangeAction, RelationResults @@ -21,6 +21,25 @@ class SnowflakeRelation(BaseRelation): type: Optional[SnowflakeRelationType] = None # type: ignore quote_policy: SnowflakeQuotePolicy = field(default_factory=lambda: SnowflakeQuotePolicy()) + renameable_relations: FrozenSet[SnowflakeRelationType] = field( + default_factory=lambda: frozenset( + { + SnowflakeRelationType.Table, + SnowflakeRelationType.View, + } + ) + ) + + replaceable_relations: FrozenSet[SnowflakeRelationType] = field( + default_factory=lambda: frozenset( + { + SnowflakeRelationType.DynamicTable, + SnowflakeRelationType.Table, + SnowflakeRelationType.View, + } + ) + ) + @property def is_dynamic_table(self) -> bool: return self.type == SnowflakeRelationType.DynamicTable diff --git a/dbt/include/snowflake/macros/relations/dynamic_table/create.sql b/dbt/include/snowflake/macros/relations/dynamic_table/create.sql new file mode 100644 index 000000000..1d76c417c --- /dev/null +++ b/dbt/include/snowflake/macros/relations/dynamic_table/create.sql @@ -0,0 +1,10 @@ +{% macro snowflake__get_create_dynamic_table_as_sql(relation, sql) -%} + + create dynamic table {{ relation }} + target_lag = '{{ config.get("target_lag") }}' + warehouse = {{ config.get("snowflake_warehouse") }} + as ( + {{ sql }} + ) + +{%- endmacro %} diff --git a/tests/unit/test_renamed_relations.py b/tests/unit/test_renamed_relations.py new file mode 100644 index 000000000..315d5f343 --- /dev/null +++ b/tests/unit/test_renamed_relations.py @@ -0,0 +1,17 @@ +from dbt.adapters.snowflake.relation import SnowflakeRelation +from dbt.adapters.snowflake.relation_configs import SnowflakeRelationType + + +def test_renameable_relation(): + relation = SnowflakeRelation.create( + database="my_db", + schema="my_schema", + identifier="my_table", + type=SnowflakeRelationType.Table, + ) + assert relation.renameable_relations == frozenset( + { + SnowflakeRelationType.Table, + SnowflakeRelationType.View, + } + )