From cefbf381edf8c2dc62165be3c1ead29cb9dd554f Mon Sep 17 00:00:00 2001 From: Mike Alfare Date: Mon, 30 Oct 2023 21:22:03 -0400 Subject: [PATCH 1/5] changelog --- .changes/unreleased/Fixes-20231030-212151.yaml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changes/unreleased/Fixes-20231030-212151.yaml diff --git a/.changes/unreleased/Fixes-20231030-212151.yaml b/.changes/unreleased/Fixes-20231030-212151.yaml new file mode 100644 index 000000000..f6c9c877c --- /dev/null +++ b/.changes/unreleased/Fixes-20231030-212151.yaml @@ -0,0 +1,6 @@ +kind: Fixes +body: Dynamic tables now show the proper type in catalog queries +time: 2023-10-30T21:21:51.220225-04:00 +custom: + Author: mikealfare + Issue: "818" From eec661c8b700f7721f196cdabd2c5f2484dbed38 Mon Sep 17 00:00:00 2001 From: Mike Alfare Date: Mon, 30 Oct 2023 21:48:27 -0400 Subject: [PATCH 2/5] create test demonstrating the issue --- .../functional/adapter/catalog_tests/files.py | 32 ++++++++++++++ .../catalog_tests/test_relation_types.py | 44 +++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 tests/functional/adapter/catalog_tests/files.py create mode 100644 tests/functional/adapter/catalog_tests/test_relation_types.py diff --git a/tests/functional/adapter/catalog_tests/files.py b/tests/functional/adapter/catalog_tests/files.py new file mode 100644 index 000000000..a6759398e --- /dev/null +++ b/tests/functional/adapter/catalog_tests/files.py @@ -0,0 +1,32 @@ +MY_SEED = """ +id,value +1,100 +2,200 +3,300 +""".strip() + + +MY_TABLE = """ +{{ config( + materialized='table', +) }} +select * from {{ ref('my_seed') }} +""" + + +MY_VIEW = """ +{{ config( + materialized='view', +) }} +select * from {{ ref('my_seed') }} +""" + + +MY_DYNAMIC_TABLE = """ +{{ config( + materialized='dynamic_table', + snowflake_warehouse='DBT_TESTING', + target_lag='30 minutes', +) }} +select * from {{ ref('my_seed') }} +""" diff --git a/tests/functional/adapter/catalog_tests/test_relation_types.py b/tests/functional/adapter/catalog_tests/test_relation_types.py new file mode 100644 index 000000000..4a3461d03 --- /dev/null +++ b/tests/functional/adapter/catalog_tests/test_relation_types.py @@ -0,0 +1,44 @@ +from dbt.contracts.results import CatalogArtifact +from dbt.tests.util import run_dbt +import pytest + +from tests.functional.adapter.dynamic_table_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_dynamic_table.sql": files.MY_DYNAMIC_TABLE, + } + + @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", "BASE TABLE"), + ("model.test.my_table", "BASE TABLE"), + ("model.test.my_view", "VIEW"), + ("model.test.my_dynamic_table", "DYNAMIC TABLE"), + ], + ) + def test_relation_types_populate_correctly( + self, docs: CatalogArtifact, node_name: str, relation_type: str + ): + """ + This test addresses: https://github.com/dbt-labs/dbt-snowflake/issues/817 + """ + assert node_name in docs.nodes + node = docs.nodes[node_name] + assert node.metadata.type == relation_type From 5bd2b08532a66a290bdb97c2f2ba5eab5ebd181e Mon Sep 17 00:00:00 2001 From: Mike Alfare Date: Mon, 30 Oct 2023 21:52:15 -0400 Subject: [PATCH 3/5] map nulls to dynamic table --- dbt/include/snowflake/macros/catalog.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dbt/include/snowflake/macros/catalog.sql b/dbt/include/snowflake/macros/catalog.sql index eaa7582e9..f0c766865 100644 --- a/dbt/include/snowflake/macros/catalog.sql +++ b/dbt/include/snowflake/macros/catalog.sql @@ -41,7 +41,7 @@ table_catalog as "table_database", table_schema as "table_schema", table_name as "table_name", - table_type as "table_type", + coalesce(table_type, 'DYNAMIC TABLE') as "table_type", comment as "table_comment", -- note: this is the _role_ that owns the table From 2d057164f28d52c67bd786d6a6b61572290cf3a4 Mon Sep 17 00:00:00 2001 From: Mike Alfare Date: Mon, 30 Oct 2023 21:53:02 -0400 Subject: [PATCH 4/5] fix issue number in changelog --- .changes/unreleased/Fixes-20231030-212151.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changes/unreleased/Fixes-20231030-212151.yaml b/.changes/unreleased/Fixes-20231030-212151.yaml index f6c9c877c..10939228f 100644 --- a/.changes/unreleased/Fixes-20231030-212151.yaml +++ b/.changes/unreleased/Fixes-20231030-212151.yaml @@ -3,4 +3,4 @@ body: Dynamic tables now show the proper type in catalog queries time: 2023-10-30T21:21:51.220225-04:00 custom: Author: mikealfare - Issue: "818" + Issue: "817" From 6c3db5bcf1389166c9a5ef2f6f9a85605fe56e4b Mon Sep 17 00:00:00 2001 From: Mike Alfare Date: Mon, 30 Oct 2023 22:11:08 -0400 Subject: [PATCH 5/5] fixed fixture import path --- tests/functional/adapter/catalog_tests/test_relation_types.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/functional/adapter/catalog_tests/test_relation_types.py b/tests/functional/adapter/catalog_tests/test_relation_types.py index 4a3461d03..27267a1c9 100644 --- a/tests/functional/adapter/catalog_tests/test_relation_types.py +++ b/tests/functional/adapter/catalog_tests/test_relation_types.py @@ -2,7 +2,7 @@ from dbt.tests.util import run_dbt import pytest -from tests.functional.adapter.dynamic_table_tests import files +from tests.functional.adapter.catalog_tests import files class TestCatalogRelationTypes: