-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ADAP-972: Fix issue where materialized views were being mapped as tab…
…les in catalog queries (#996) * changelog * add test demonstrating issue * update catalog query to correctly identify materialized views (cherry picked from commit f6e26d0)
- Loading branch information
1 parent
381b859
commit b0935e6
Showing
4 changed files
with
109 additions
and
14 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: Assign the correct relation type to materialized views in catalog queries | ||
time: 2023-10-30T22:21:34.401675-04:00 | ||
custom: | ||
Author: mikealfare | ||
Issue: "995" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
MY_SEED = """ | ||
id,value,record_valid_date | ||
1,100,2023-01-01 00:00:00 | ||
2,200,2023-01-02 00:00:00 | ||
3,300,2023-01-02 00:00:00 | ||
""".strip() | ||
|
||
|
||
MY_TABLE = """ | ||
{{ config( | ||
materialized='table', | ||
) }} | ||
select * | ||
from {{ ref('my_seed') }} | ||
""" | ||
|
||
|
||
MY_VIEW = """ | ||
{{ config( | ||
materialized='view', | ||
) }} | ||
select * | ||
from {{ ref('my_seed') }} | ||
""" | ||
|
||
|
||
MY_MATERIALIZED_VIEW = """ | ||
{{ config( | ||
materialized='materialized_view', | ||
) }} | ||
select * | ||
from {{ ref('my_table') }} | ||
""" |
44 changes: 44 additions & 0 deletions
44
tests/functional/adapter/catalog_tests/test_relation_types.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,44 @@ | ||
from dbt.contracts.results import CatalogArtifact | ||
from dbt.tests.util import run_dbt | ||
import pytest | ||
|
||
from tests.functional.adapter.catalog_tests import files | ||
|
||
|
||
class TestCatalogRelationTypes: | ||
@pytest.fixture(scope="class", autouse=True) | ||
def seeds(self): | ||
return {"my_seed.csv": files.MY_SEED} | ||
|
||
@pytest.fixture(scope="class", autouse=True) | ||
def models(self): | ||
yield { | ||
"my_table.sql": files.MY_TABLE, | ||
"my_view.sql": files.MY_VIEW, | ||
"my_materialized_view.sql": files.MY_MATERIALIZED_VIEW, | ||
} | ||
|
||
@pytest.fixture(scope="class", autouse=True) | ||
def docs(self, project): | ||
run_dbt(["seed"]) | ||
run_dbt(["run"]) | ||
yield run_dbt(["docs", "generate"]) | ||
|
||
@pytest.mark.parametrize( | ||
"node_name,relation_type", | ||
[ | ||
("seed.test.my_seed", "table"), | ||
("model.test.my_table", "table"), | ||
("model.test.my_view", "view"), | ||
("model.test.my_materialized_view", "materialized view"), | ||
], | ||
) | ||
def test_relation_types_populate_correctly( | ||
self, docs: CatalogArtifact, node_name: str, relation_type: str | ||
): | ||
""" | ||
This test addresses: https://github.com/dbt-labs/dbt-bigquery/issues/995 | ||
""" | ||
assert node_name in docs.nodes | ||
node = docs.nodes[node_name] | ||
assert node.metadata.type == relation_type |