Skip to content

Commit

Permalink
Add test and move semantics.
Browse files Browse the repository at this point in the history
  • Loading branch information
VersusFacit committed Feb 27, 2024
1 parent 2c0b16f commit d00cb37
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 14 deletions.
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"
46 changes: 33 additions & 13 deletions dbt/adapters/snowflake/relation.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,27 @@
@dataclass(frozen=True, eq=False, repr=False)
class SnowflakeRelation(BaseRelation):
type: Optional[SnowflakeRelationType] = None # type: ignore
quote_policy: SnowflakeQuotePolicy = field(default_factory=lambda: SnowflakeQuotePolicy())
renameable_relations = frozenset({SnowflakeRelationType.Table, SnowflakeRelationType.View})
replaceable_relations = frozenset(
{
SnowflakeRelationType.DynamicTable,
SnowflakeRelationType.Table,
SnowflakeRelationType.View,
}
quote_policy: SnowflakeQuotePolicy = field(
default_factory=lambda: SnowflakeQuotePolicy()
)

renameable_relations: FrozenSet[RelationType] = field(
default_factory=lambda: frozenset(
{
SnowflakeRelationType.Table,
SnowflakeRelationType.View,
}
)
)

replaceable_relations: FrozenSet[RelationType] = field(
default_factory=lambda: frozenset(
{
SnowflakeRelationType.DynamicTable,
SnowflakeRelationType.Table,
SnowflakeRelationType.View,
}
)
)

@property
Expand All @@ -48,17 +61,24 @@ def dynamic_table_config_changeset(
existing_dynamic_table = SnowflakeDynamicTableConfig.from_relation_results(
relation_results
)
new_dynamic_table = SnowflakeDynamicTableConfig.from_relation_config(relation_config)
new_dynamic_table = SnowflakeDynamicTableConfig.from_relation_config(
relation_config
)

config_change_collection = SnowflakeDynamicTableConfigChangeset()

if new_dynamic_table.target_lag != existing_dynamic_table.target_lag:
config_change_collection.target_lag = SnowflakeDynamicTableTargetLagConfigChange(
action=RelationConfigChangeAction.alter,
context=new_dynamic_table.target_lag,
config_change_collection.target_lag = (
SnowflakeDynamicTableTargetLagConfigChange(
action=RelationConfigChangeAction.alter,
context=new_dynamic_table.target_lag,
)
)

if new_dynamic_table.snowflake_warehouse != existing_dynamic_table.snowflake_warehouse:
if (
new_dynamic_table.snowflake_warehouse
!= existing_dynamic_table.snowflake_warehouse
):
config_change_collection.snowflake_warehouse = (
SnowflakeDynamicTableWarehouseConfigChange(
action=RelationConfigChangeAction.alter,
Expand Down
2 changes: 1 addition & 1 deletion dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# install latest changes in dbt-core
# TODO: how to automate switching from develop to version branches?
git+https://github.com/dbt-labs/dbt-core.git#egg=dbt-core&subdirectory=core
git+https://github.com/dbt-labs/dbt-adapters.git
git+https://github.com/dbt-labs/dbt-adapters.git@ADAP-108/fix_renamed_relations_for_1.8
git+https://github.com/dbt-labs/dbt-adapters.git#subdirectory=dbt-tests-adapter

# if version 1.x or greater -> pin to major version
Expand Down
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.contracts.relation import RelationType


def test_renameable_relation():
relation = SnowflakeRelation.create(
database="my_db",
schema="my_schema",
identifier="my_table",
type=RelationType.Table,
)
assert relation.renameable_relations == frozenset(
{
SnowflakeRelationType.Table,
SnowflakeRelationType.View,
}
)

0 comments on commit d00cb37

Please sign in to comment.