-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Materialized Views not updating cache (#9959)
* initial push of adding cache functions for materialized views * update * add cache_renamed * remove current attempt of add cache_renamed * add checks for add, and drop to see if relation exists in dispatch macro * move calls from distpach macro into the default call/postgres specific versions incase we are not catching the dispatch as a layer of call or in drop case of it being a explicit return call * split up relation into parts to build up to_relation * move cache_dropped back to the dispatch original dispatch macro * move cache_dropped back to the dispatch original dispatch macro * readd removed space between macros * move cache_added back to distpach macro * remove extra curly brace * revert get_relation call back get cache_renamed * move of cache_renamed to get_rename_sql * remove updated cache_changes and remove Relation.MaterializedView from renabmeable (takes us back to previous functionality) * add changelog * add simple test case, and doc string
- Loading branch information
1 parent
7122b31
commit ad0df69
Showing
5 changed files
with
72 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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-23T17:24:07.249421-05:00 | ||
custom: | ||
Author: McKnight-42 | ||
Issue: "127" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
tests/functional/materializations/materialized_view_tests/test_posgres_materialized_view.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
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"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,5 @@ def test_renameable_relation(): | |
{ | ||
RelationType.View, | ||
RelationType.Table, | ||
RelationType.MaterializedView, | ||
} | ||
) |