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

Fix the renamed relations code #723

Merged
merged 10 commits into from
Mar 21, 2024
6 changes: 6 additions & 0 deletions .changes/unreleased/Under the Hood-20240227-002713.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-27T00:27:13.299107-08:00
custom:
Author: versusfacit
Issue: "722"
26 changes: 15 additions & 11 deletions dbt/adapters/redshift/relation.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from dataclasses import dataclass
from dataclasses import dataclass, field
from dbt.adapters.contracts.relation import RelationConfig
from typing import Optional
from typing import FrozenSet, Optional

from dbt.adapters.base.relation import BaseRelation
from dbt.adapters.relation_configs import (
Expand Down Expand Up @@ -30,16 +30,20 @@ class RedshiftRelation(BaseRelation):
relation_configs = {
RelationType.MaterializedView.value: RedshiftMaterializedViewConfig,
}
renameable_relations = frozenset(
{
RelationType.View,
RelationType.Table,
}
renameable_relations: FrozenSet[RelationType] = field(
default_factory=lambda: frozenset(
{
RelationType.View,
RelationType.Table,
}
)
)
replaceable_relations = frozenset(
{
RelationType.View,
}
replaceable_relations: FrozenSet[RelationType] = field(
default_factory=lambda: frozenset(
{
RelationType.View,
}
)
)

def __post_init__(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
auto refresh {% if materialized_view.autorefresh %}yes{% else %}no{% endif %}
as (
{{ materialized_view.query }}
);
)

{% endmacro %}
2 changes: 1 addition & 1 deletion dbt/include/redshift/macros/relations/view/rename.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{% macro redshift__get_rename_view_sql(relation, new_name) %}
alter view {{ relation }} rename to {{ new_name }}
alter table {{ relation }} rename to {{ new_name }}
{% endmacro %}
2 changes: 1 addition & 1 deletion dbt/include/redshift/macros/relations/view/replace.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
{{ get_assert_columns_equivalent(sql) }}
{%- endif %} as (
{{ sql }}
) {{ bind_qualifier }};
) {{ bind_qualifier }}

{%- 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.redshift.relation import RedshiftRelation
from dbt.adapters.contracts.relation import RelationType


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