From eb6b2fbf8a1bc4ae28176d55088425c60a6207c5 Mon Sep 17 00:00:00 2001 From: Colin Date: Wed, 17 Apr 2024 15:49:47 -0700 Subject: [PATCH 1/5] add test --- dbt/adapters/snowflake/relation.py | 9 ++++++++ tests/functional/adapter/empty/test_empty.py | 23 +++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/dbt/adapters/snowflake/relation.py b/dbt/adapters/snowflake/relation.py index ae037aebc..bcde48962 100644 --- a/dbt/adapters/snowflake/relation.py +++ b/dbt/adapters/snowflake/relation.py @@ -80,3 +80,12 @@ def dynamic_table_config_changeset( if config_change_collection.has_changes: return config_change_collection return None + + def render_limited(self) -> str: + rendered = self.render() + if self.limit is None: + return rendered + elif self.limit == 0: + return f"(select * from {rendered} where false limit 0)" + else: + return f"(select * from {rendered} limit {self.limit})" diff --git a/tests/functional/adapter/empty/test_empty.py b/tests/functional/adapter/empty/test_empty.py index 37aa45f60..d7870a616 100644 --- a/tests/functional/adapter/empty/test_empty.py +++ b/tests/functional/adapter/empty/test_empty.py @@ -1,5 +1,26 @@ -from dbt.tests.adapter.empty.test_empty import BaseTestEmpty +import pytest +from dbt.tests.adapter.empty.test_empty import BaseTestEmpty, schema_sources_yml class TestSnowflakeEmpty(BaseTestEmpty): pass + + +class TestSnowflakeEmptyInlineSourceRef(BaseTestEmpty): + @pytest.fixture(scope="class") + def models(self): + model_sql = """ + select * from {{ source('seed_sources', 'raw_source') }} as raw_source + """ + + return { + "model.sql": model_sql, + "sources.yml": schema_sources_yml, + } + + def test_run_with_empty(self, project): + # create source from seed + project.run_dbt(["seed"]) + + project.run_dbt(["run", "--empty"]) + self.assert_row_count(project, "model", 0) From 5bed1c48c4290d81556ca1674ce337ba954f1b54 Mon Sep 17 00:00:00 2001 From: Colin Date: Thu, 18 Apr 2024 15:51:41 -0700 Subject: [PATCH 2/5] add changie --- dbt/adapters/snowflake/relation.py | 11 +--------- dev-requirements.txt | 4 ++-- tests/functional/adapter/empty/test_empty.py | 23 +++----------------- 3 files changed, 6 insertions(+), 32 deletions(-) diff --git a/dbt/adapters/snowflake/relation.py b/dbt/adapters/snowflake/relation.py index bcde48962..23952287c 100644 --- a/dbt/adapters/snowflake/relation.py +++ b/dbt/adapters/snowflake/relation.py @@ -20,7 +20,7 @@ class SnowflakeRelation(BaseRelation): type: Optional[SnowflakeRelationType] = None # type: ignore quote_policy: SnowflakeQuotePolicy = field(default_factory=lambda: SnowflakeQuotePolicy()) - + require_alias: bool = False renameable_relations: FrozenSet[SnowflakeRelationType] = field( default_factory=lambda: frozenset( { @@ -80,12 +80,3 @@ def dynamic_table_config_changeset( if config_change_collection.has_changes: return config_change_collection return None - - def render_limited(self) -> str: - rendered = self.render() - if self.limit is None: - return rendered - elif self.limit == 0: - return f"(select * from {rendered} where false limit 0)" - else: - return f"(select * from {rendered} limit {self.limit})" diff --git a/dev-requirements.txt b/dev-requirements.txt index 6f4fd46ae..66ddad822 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -1,8 +1,8 @@ # install latest changes in dbt-core # TODO: how to automate switching from develop to version branches? git+https://github.com/dbt-labs/dbt-core.git#egg=dbt-core&subdirectory=core -git+https://github.com/dbt-labs/dbt-adapters.git -git+https://github.com/dbt-labs/dbt-adapters.git#subdirectory=dbt-tests-adapter +git+https://github.com/dbt-labs/dbt-adapters.git@makeAliasingOptional +git+https://github.com/dbt-labs/dbt-adapters.git@makeAliasingOptional#subdirectory=dbt-tests-adapter # if version 1.x or greater -> pin to major version # if version 0.x -> pin to minor diff --git a/tests/functional/adapter/empty/test_empty.py b/tests/functional/adapter/empty/test_empty.py index d7870a616..401179b71 100644 --- a/tests/functional/adapter/empty/test_empty.py +++ b/tests/functional/adapter/empty/test_empty.py @@ -1,26 +1,9 @@ -import pytest -from dbt.tests.adapter.empty.test_empty import BaseTestEmpty, schema_sources_yml +from dbt.tests.adapter.empty.test_empty import BaseTestEmpty, BaseTestEmptyInlineSourceRef class TestSnowflakeEmpty(BaseTestEmpty): pass -class TestSnowflakeEmptyInlineSourceRef(BaseTestEmpty): - @pytest.fixture(scope="class") - def models(self): - model_sql = """ - select * from {{ source('seed_sources', 'raw_source') }} as raw_source - """ - - return { - "model.sql": model_sql, - "sources.yml": schema_sources_yml, - } - - def test_run_with_empty(self, project): - # create source from seed - project.run_dbt(["seed"]) - - project.run_dbt(["run", "--empty"]) - self.assert_row_count(project, "model", 0) +class TestSnowflakeEmptyInlineSourceRef(BaseTestEmptyInlineSourceRef): + pass From 911e0f2dd641e4d01944792d91bb765b87217121 Mon Sep 17 00:00:00 2001 From: Colin Date: Thu, 18 Apr 2024 16:02:53 -0700 Subject: [PATCH 3/5] add changie --- .changes/unreleased/Fixes-20240418-160240.yaml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changes/unreleased/Fixes-20240418-160240.yaml diff --git a/.changes/unreleased/Fixes-20240418-160240.yaml b/.changes/unreleased/Fixes-20240418-160240.yaml new file mode 100644 index 000000000..a9932def6 --- /dev/null +++ b/.changes/unreleased/Fixes-20240418-160240.yaml @@ -0,0 +1,6 @@ +kind: Fixes +body: Fix duplicate alias being added when running a model with inline refs and `--empty` +time: 2024-04-18T16:02:40.488967-07:00 +custom: + Author: colin-rogers-dbt + Issue: "980" From b6575f30348066cf325a67444640aa2ebdc20ac8 Mon Sep 17 00:00:00 2001 From: Colin Date: Thu, 18 Apr 2024 16:12:38 -0700 Subject: [PATCH 4/5] fix unit test import --- tests/unit/test_snowflake_adapter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/test_snowflake_adapter.py b/tests/unit/test_snowflake_adapter.py index a9f8f3572..2666e7557 100644 --- a/tests/unit/test_snowflake_adapter.py +++ b/tests/unit/test_snowflake_adapter.py @@ -10,7 +10,7 @@ from dbt.adapters.snowflake.column import SnowflakeColumn from dbt.adapters.snowflake.connections import SnowflakeCredentials from dbt.contracts.files import FileHash -from dbt.context.manifest import generate_query_header_context +from dbt.context.query_header import generate_query_header_context from dbt.context.providers import generate_runtime_macro_context from dbt.contracts.graph.manifest import ManifestStateCheck from dbt_common.clients import agate_helper From 79215e68765453e9aa50b7715d8364b7791b63e9 Mon Sep 17 00:00:00 2001 From: Colin Date: Mon, 22 Apr 2024 09:58:29 -0700 Subject: [PATCH 5/5] remove branch pointer from dev-requirements.txt --- dev-requirements.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dev-requirements.txt b/dev-requirements.txt index 66ddad822..6f4fd46ae 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -1,8 +1,8 @@ # install latest changes in dbt-core # TODO: how to automate switching from develop to version branches? git+https://github.com/dbt-labs/dbt-core.git#egg=dbt-core&subdirectory=core -git+https://github.com/dbt-labs/dbt-adapters.git@makeAliasingOptional -git+https://github.com/dbt-labs/dbt-adapters.git@makeAliasingOptional#subdirectory=dbt-tests-adapter +git+https://github.com/dbt-labs/dbt-adapters.git +git+https://github.com/dbt-labs/dbt-adapters.git#subdirectory=dbt-tests-adapter # if version 1.x or greater -> pin to major version # if version 0.x -> pin to minor