diff --git a/.changes/unreleased/Fixes-20240423-180916.yaml b/.changes/unreleased/Fixes-20240423-180916.yaml new file mode 100644 index 00000000..48015bcb --- /dev/null +++ b/.changes/unreleased/Fixes-20240423-180916.yaml @@ -0,0 +1,6 @@ +kind: Fixes +body: remove materialized views from renambeable relation and remove a quote +time: 2024-04-23T18:09:16.865258-05:00 +custom: + Author: McKnight-42 + Issue: "127" diff --git a/dbt/adapters/postgres/relation.py b/dbt/adapters/postgres/relation.py index 05d55237..e546eab4 100644 --- a/dbt/adapters/postgres/relation.py +++ b/dbt/adapters/postgres/relation.py @@ -25,7 +25,6 @@ class PostgresRelation(BaseRelation): { RelationType.View, RelationType.Table, - RelationType.MaterializedView, } ) ) diff --git a/dbt/include/postgres/macros/adapters.sql b/dbt/include/postgres/macros/adapters.sql index ee864e9b..294443be 100644 --- a/dbt/include/postgres/macros/adapters.sql +++ b/dbt/include/postgres/macros/adapters.sql @@ -39,7 +39,7 @@ on {{ relation }} {% if index_config.type -%} using {{ index_config.type }} {%- endif %} - ({{ comma_separated_columns }}); + ({{ comma_separated_columns }}) {%- endmacro %} {% macro postgres__create_schema(relation) -%} diff --git a/tests/functional/materializations/materialized_view_tests/test_postgres_materialized_view.py b/tests/functional/materializations/materialized_view_tests/test_postgres_materialized_view.py new file mode 100644 index 00000000..4ee44bae --- /dev/null +++ b/tests/functional/materializations/materialized_view_tests/test_postgres_materialized_view.py @@ -0,0 +1,63 @@ +import pytest +from dbt.tests.util import run_dbt + +SEED = """ +order_id,customer_id,total_amount,order_date +1,101,50.00,2024-04-01 +2,102,75.00,2024-04-02 +3,103,100.00,2024-04-03 +4,101,30.00,2024-04-04 +5,104,45.00,2024-04-05 +""".strip() + +ORDERS = """ +-- models/orders.sql +{{ + config( + materialized='materialized_view' + ) +}} +SELECT + order_id, + customer_id, + total_amount, + order_date +FROM + {{ ref('source_orders') }} +""" + +PRODUCT_SALES = """ +{{ + config( + materialized='materialized_view' + ) +}} +SELECT + order_id, + SUM(total_amount) AS total_sales_amount +FROM + {{ ref('orders') }} +GROUP BY + order_id +""" + + +class TestPostgresTestRefreshMaterializedView: + """ + this test addresses a issue in postgres around materialized views, + and renaming against a model who has dependent models that are also materialized views + related pr: https://github.com/dbt-labs/dbt-core/pull/9959 + """ + + @pytest.fixture(scope="class") + def models(self): + yield {"orders.sql": ORDERS, "product_sales.sql": PRODUCT_SALES} + + @pytest.fixture(scope="class") + def seeds(self): + yield {"source_orders.csv": SEED} + + def test_postgres_refresh_dependent_naterialized_views(self, project): + run_dbt(["seed"]) + run_dbt(["run", "--full-refresh"]) + run_dbt(["run", "--full-refresh"]) diff --git a/tests/unit/test_renamed_relations.py b/tests/unit/test_renamed_relations.py index 29bbabf2..5d2bcb04 100644 --- a/tests/unit/test_renamed_relations.py +++ b/tests/unit/test_renamed_relations.py @@ -13,6 +13,5 @@ def test_renameable_relation(): { RelationType.View, RelationType.Table, - RelationType.MaterializedView, } )