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

Materialized Views not updating cache #69

Merged
merged 2 commits into from
Apr 24, 2024
Merged
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/Fixes-20240423-180916.yaml
Original file line number Diff line number Diff line change
@@ -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"
1 change: 0 additions & 1 deletion dbt/adapters/postgres/relation.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class PostgresRelation(BaseRelation):
{
RelationType.View,
RelationType.Table,
RelationType.MaterializedView,
}
)
)
Expand Down
2 changes: 1 addition & 1 deletion dbt/include/postgres/macros/adapters.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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) -%}
Expand Down
Original file line number Diff line number Diff line change
@@ -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"])
1 change: 0 additions & 1 deletion tests/unit/test_renamed_relations.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,5 @@ def test_renameable_relation():
{
RelationType.View,
RelationType.Table,
RelationType.MaterializedView,
}
)
Loading