Skip to content
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

[Backport 1.6.latest] Add test and move semantics. #947

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changes/unreleased/Under the Hood-20240227-010428.yaml
Original file line number Diff line number Diff line change
@@ -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"
21 changes: 20 additions & 1 deletion dbt/adapters/snowflake/relation.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
10 changes: 10 additions & 0 deletions dbt/include/snowflake/macros/relations/dynamic_table/create.sql
Original file line number Diff line number Diff line change
@@ -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 %}
17 changes: 17 additions & 0 deletions tests/unit/test_renamed_relations.py
Original file line number Diff line number Diff line change
@@ -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,
}
)
Loading