-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add drop cascade for materialized views
- Loading branch information
1 parent
8bbdbf2
commit d189acb
Showing
6 changed files
with
67 additions
and
1 deletion.
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,7 @@ | ||
kind: Fixes | ||
body: Support DROP CASCADE for materialized views; fixes bug that occurs when running | ||
dbt on materialized views that reference other materialized views | ||
time: 2024-09-06T10:26:42.501014-04:00 | ||
custom: | ||
Author: mikealfare | ||
Issue: "642" |
2 changes: 1 addition & 1 deletion
2
dbt/include/redshift/macros/relations/materialized_view/drop.sql
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{% macro redshift__drop_materialized_view(relation) -%} | ||
drop materialized view if exists {{ relation }} | ||
drop materialized view if exists {{ relation }} cascade | ||
{%- endmacro %} |
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 @@ | ||
# provides namespacing for test discovery |
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 @@ | ||
# provides namespacing for test discovery |
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 @@ | ||
# provides namespacing for test discovery |
56 changes: 56 additions & 0 deletions
56
tests/functional/adapter/materialized_view_tests/test_drop_cascade.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,56 @@ | ||
""" | ||
This test addresses this bug: https://github.com/dbt-labs/dbt-redshift/issues/642 | ||
Redshift did not initially support DROP CASCADE for materialized views, | ||
or at least did not document that they did. Now that they do, we should | ||
use DROP CASCADE instead of DROP. | ||
""" | ||
|
||
from dbt.tests.util import run_dbt | ||
import pytest | ||
|
||
|
||
SEED = """ | ||
id | ||
1 | ||
""".strip() | ||
|
||
|
||
PARENT_MATERIALIZED_VIEW = """ | ||
{{ config( | ||
materialized='materialized_view', | ||
on_configuration_change='apply', | ||
) }} | ||
select * from {{ ref('my_seed') }} | ||
""" | ||
|
||
|
||
CHILD_MATERIALIZED_VIEW = """ | ||
{{ config( | ||
materialized='materialized_view', | ||
on_configuration_change='apply', | ||
) }} | ||
select * from {{ ref('parent_mv') }} | ||
""" | ||
|
||
|
||
@pytest.fixture(scope="class") | ||
def seeds(): | ||
return {"my_seed.csv": SEED} | ||
|
||
|
||
@pytest.fixture(scope="class") | ||
def models(): | ||
return { | ||
"parent_mv.sql": PARENT_MATERIALIZED_VIEW, | ||
"child_mv.sql": CHILD_MATERIALIZED_VIEW, | ||
} | ||
|
||
|
||
def test_drop_cascade(project): | ||
run_dbt(["seed"]) | ||
run_dbt(["run"]) | ||
# this originally raised an error when it should not have | ||
run_dbt(["run", "--full-refresh"]) |