From c668ca5af13536880c72fe00f314e14bb2c96756 Mon Sep 17 00:00:00 2001 From: Mila Page <67295367+VersusFacit@users.noreply.github.com> Date: Thu, 21 Mar 2024 08:31:24 -0700 Subject: [PATCH] Fix the renamed relations code (#1125) * Add test and move semantics. * Add field import --------- Co-authored-by: Mila Page Co-authored-by: Mike Alfare Co-authored-by: Mike Alfare <13974384+mikealfare@users.noreply.github.com> (cherry picked from commit 40024838e58e41385d4b4659fbd677faa5955725) --- .../Under the Hood-20240227-004659.yaml | 6 ++++++ dbt/adapters/bigquery/relation.py | 21 +++++++++++++++---- tests/unit/test_renamed_relations.py | 16 ++++++++++++++ 3 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 .changes/unreleased/Under the Hood-20240227-004659.yaml create mode 100644 tests/unit/test_renamed_relations.py diff --git a/.changes/unreleased/Under the Hood-20240227-004659.yaml b/.changes/unreleased/Under the Hood-20240227-004659.yaml new file mode 100644 index 000000000..6ef259019 --- /dev/null +++ b/.changes/unreleased/Under the Hood-20240227-004659.yaml @@ -0,0 +1,6 @@ +kind: Under the Hood +body: Add unit test for transaction semantics. +time: 2024-02-27T00:46:59.188231-08:00 +custom: + Author: versusfacit + Issue: "1123" diff --git a/dbt/adapters/bigquery/relation.py b/dbt/adapters/bigquery/relation.py index c14dba238..0673fd06d 100644 --- a/dbt/adapters/bigquery/relation.py +++ b/dbt/adapters/bigquery/relation.py @@ -1,4 +1,4 @@ -from dataclasses import dataclass +from dataclasses import dataclass, field from typing import FrozenSet, Optional, TypeVar from itertools import chain, islice @@ -25,9 +25,22 @@ class BigQueryRelation(BaseRelation): quote_character: str = "`" location: Optional[str] = None - renameable_relations: FrozenSet[RelationType] = frozenset({RelationType.Table}) - replaceable_relations: FrozenSet[RelationType] = frozenset( - {RelationType.Table, RelationType.View} + + renameable_relations: FrozenSet[RelationType] = field( + default_factory=lambda: frozenset( + { + RelationType.Table, + } + ) + ) + + replaceable_relations: FrozenSet[RelationType] = field( + default_factory=lambda: frozenset( + { + RelationType.View, + RelationType.Table, + } + ) ) def matches( diff --git a/tests/unit/test_renamed_relations.py b/tests/unit/test_renamed_relations.py new file mode 100644 index 000000000..8e787e6a3 --- /dev/null +++ b/tests/unit/test_renamed_relations.py @@ -0,0 +1,16 @@ +from dbt.adapters.bigquery.relation import BigQueryRelation +from dbt.adapters.contracts.relation import RelationType + + +def test_renameable_relation(): + relation = BigQueryRelation.create( + database="my_db", + schema="my_schema", + identifier="my_table", + type=RelationType.Table, + ) + assert relation.renameable_relations == frozenset( + { + RelationType.Table, + } + )