From 73b6a1203c305424370de3fc1bd511fe39b0a9c8 Mon Sep 17 00:00:00 2001 From: Mila Page <67295367+VersusFacit@users.noreply.github.com> Date: Thu, 21 Mar 2024 07:43:41 -0700 Subject: [PATCH 1/3] Add test and move semantics. (#913) * Add test and move semantics * Add FrozenSet to imports * Tweak test failures * remove extra semicolon --------- Co-authored-by: Mila Page Co-authored-by: Mike Alfare <13974384+mikealfare@users.noreply.github.com> Co-authored-by: Mike Alfare --- .../Under the Hood-20240227-010428.yaml | 6 +++++ dbt/adapters/snowflake/relation.py | 27 +++++++++++++------ .../macros/relations/dynamic_table/create.sql | 1 - tests/unit/test_renamed_relations.py | 17 ++++++++++++ 4 files changed, 42 insertions(+), 9 deletions(-) create mode 100644 .changes/unreleased/Under the Hood-20240227-010428.yaml create mode 100644 tests/unit/test_renamed_relations.py diff --git a/.changes/unreleased/Under the Hood-20240227-010428.yaml b/.changes/unreleased/Under the Hood-20240227-010428.yaml new file mode 100644 index 000000000..5252d0313 --- /dev/null +++ b/.changes/unreleased/Under the Hood-20240227-010428.yaml @@ -0,0 +1,6 @@ +kind: Under the Hood +body: Add unit test for transaction semantics. +time: 2024-02-27T01:04:28.713433-08:00 +custom: + Author: versusfacit + Issue: "912" diff --git a/dbt/adapters/snowflake/relation.py b/dbt/adapters/snowflake/relation.py index 325d23c9b..ae037aebc 100644 --- a/dbt/adapters/snowflake/relation.py +++ b/dbt/adapters/snowflake/relation.py @@ -1,5 +1,5 @@ from dataclasses import dataclass, field -from typing import Optional, Type +from typing import FrozenSet, Optional, Type from dbt.adapters.base.relation import BaseRelation from dbt.adapters.relation_configs import RelationConfigChangeAction, RelationResults @@ -20,13 +20,24 @@ class SnowflakeRelation(BaseRelation): type: Optional[SnowflakeRelationType] = None # type: ignore quote_policy: SnowflakeQuotePolicy = field(default_factory=lambda: SnowflakeQuotePolicy()) - renameable_relations = frozenset({SnowflakeRelationType.Table, SnowflakeRelationType.View}) - replaceable_relations = frozenset( - { - SnowflakeRelationType.DynamicTable, - SnowflakeRelationType.Table, - SnowflakeRelationType.View, - } + + renameable_relations: FrozenSet[SnowflakeRelationType] = field( + default_factory=lambda: frozenset( + { + SnowflakeRelationType.Table, + SnowflakeRelationType.View, + } + ) + ) + + replaceable_relations: FrozenSet[SnowflakeRelationType] = field( + default_factory=lambda: frozenset( + { + SnowflakeRelationType.DynamicTable, + SnowflakeRelationType.Table, + SnowflakeRelationType.View, + } + ) ) @property diff --git a/dbt/include/snowflake/macros/relations/dynamic_table/create.sql b/dbt/include/snowflake/macros/relations/dynamic_table/create.sql index 8e8f3287f..1d76c417c 100644 --- a/dbt/include/snowflake/macros/relations/dynamic_table/create.sql +++ b/dbt/include/snowflake/macros/relations/dynamic_table/create.sql @@ -6,6 +6,5 @@ as ( {{ sql }} ) - ; {%- endmacro %} diff --git a/tests/unit/test_renamed_relations.py b/tests/unit/test_renamed_relations.py new file mode 100644 index 000000000..315d5f343 --- /dev/null +++ b/tests/unit/test_renamed_relations.py @@ -0,0 +1,17 @@ +from dbt.adapters.snowflake.relation import SnowflakeRelation +from dbt.adapters.snowflake.relation_configs import SnowflakeRelationType + + +def test_renameable_relation(): + relation = SnowflakeRelation.create( + database="my_db", + schema="my_schema", + identifier="my_table", + type=SnowflakeRelationType.Table, + ) + assert relation.renameable_relations == frozenset( + { + SnowflakeRelationType.Table, + SnowflakeRelationType.View, + } + ) From ad7ea4dcd23733e08f10571113a94012ec3a4e28 Mon Sep 17 00:00:00 2001 From: Mike Alfare <13974384+mikealfare@users.noreply.github.com> Date: Thu, 21 Mar 2024 15:40:00 -0400 Subject: [PATCH 2/3] Acknowledge `send_anonymous_usage_stats` setting for python models (#933) * add draft integration test demonstrating the issue * changie * condition on the send_anonymous_usage_stats setting when building a python model --- .../unreleased/Fixes-20240318-203635.yaml | 6 +++ dbt/adapters/snowflake/impl.py | 7 ++- .../adapter/test_anonymous_usage_stats.py | 43 +++++++++++++++++++ 3 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 .changes/unreleased/Fixes-20240318-203635.yaml create mode 100644 tests/functional/adapter/test_anonymous_usage_stats.py diff --git a/.changes/unreleased/Fixes-20240318-203635.yaml b/.changes/unreleased/Fixes-20240318-203635.yaml new file mode 100644 index 000000000..d2c1cd05f --- /dev/null +++ b/.changes/unreleased/Fixes-20240318-203635.yaml @@ -0,0 +1,6 @@ +kind: Fixes +body: Acknowledge `send_anonymous_usage_stats` setting for python models +time: 2024-03-18T20:36:35.396323-04:00 +custom: + Author: mikealfare + Issue: "830" diff --git a/dbt/adapters/snowflake/impl.py b/dbt/adapters/snowflake/impl.py index 4dc57a1b4..3583c888c 100644 --- a/dbt/adapters/snowflake/impl.py +++ b/dbt/adapters/snowflake/impl.py @@ -217,10 +217,13 @@ def submit_python_job(self, parsed_model: dict, compiled_code: str): if imports: imports = f"IMPORTS = ('{imports}')" - snowpark_telemetry_string = "dbtLabs_dbtPython" - snowpark_telemetry_snippet = f""" + if self.config.args.SEND_ANONYMOUS_USAGE_STATS: + snowpark_telemetry_string = "dbtLabs_dbtPython" + snowpark_telemetry_snippet = f""" import sys sys._xoptions['snowflake_partner_attribution'].append("{snowpark_telemetry_string}")""" + else: + snowpark_telemetry_snippet = "" common_procedure_code = f""" RETURNS STRING diff --git a/tests/functional/adapter/test_anonymous_usage_stats.py b/tests/functional/adapter/test_anonymous_usage_stats.py new file mode 100644 index 000000000..bc5a4d334 --- /dev/null +++ b/tests/functional/adapter/test_anonymous_usage_stats.py @@ -0,0 +1,43 @@ +from dbt.tests.util import run_dbt_and_capture +import pytest + + +ANONYMOUS_USAGE_MESSAGE = """ +sys._xoptions['snowflake_partner_attribution'].append("dbtLabs_dbtPython") +""".strip() + + +MY_PYTHON_MODEL = """ +import pandas + +def model(dbt, session): + dbt.config(materialized='table') + data = [[1,2]] * 10 + return pandas.DataFrame(data, columns=['test', 'test2']) +""" + + +class AnonymousUsageStatsBase: + @pytest.fixture(scope="class") + def models(self): + return {"my_python_model.py": MY_PYTHON_MODEL} + + +class TestAnonymousUsageStatsOn(AnonymousUsageStatsBase): + @pytest.fixture(scope="class") + def project_config_update(self): + return {"flags": {"send_anonymous_usage_stats": True}} + + def test_stats_get_sent(self, project): + _, logs = run_dbt_and_capture(["--debug", "run"]) + assert ANONYMOUS_USAGE_MESSAGE in logs + + +class TestAnonymousUsageStatsOff(AnonymousUsageStatsBase): + @pytest.fixture(scope="class") + def project_config_update(self, dbt_profile_target): + return {"flags": {"send_anonymous_usage_stats": False}} + + def test_stats_do_not_get_sent(self, project): + _, logs = run_dbt_and_capture(["--debug", "run"]) + assert ANONYMOUS_USAGE_MESSAGE not in logs From 1b5c165c9c5c441131c7d2d4ac523182fb0dcbf4 Mon Sep 17 00:00:00 2001 From: Matthew McKnight <91097623+McKnight-42@users.noreply.github.com> Date: Mon, 25 Mar 2024 12:32:16 -0500 Subject: [PATCH 3/3] Remove private_key_path from _conection_keys (#950) * update RELEASE_BRANCH env * remove private_key_path from _connections * add changelog --- .changes/unreleased/Fixes-20240322-104553.yaml | 6 ++++++ dbt/adapters/snowflake/connections.py | 1 - 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 .changes/unreleased/Fixes-20240322-104553.yaml diff --git a/.changes/unreleased/Fixes-20240322-104553.yaml b/.changes/unreleased/Fixes-20240322-104553.yaml new file mode 100644 index 000000000..21c037462 --- /dev/null +++ b/.changes/unreleased/Fixes-20240322-104553.yaml @@ -0,0 +1,6 @@ +kind: Fixes +body: remove `private_key_path` from connection keys +time: 2024-03-22T10:45:53.598328-05:00 +custom: + Author: McKnight-42 + Issue: "949" diff --git a/dbt/adapters/snowflake/connections.py b/dbt/adapters/snowflake/connections.py index 955357231..fcd16aafc 100644 --- a/dbt/adapters/snowflake/connections.py +++ b/dbt/adapters/snowflake/connections.py @@ -125,7 +125,6 @@ def _connection_keys(self): "role", "schema", "authenticator", - "private_key_path", "oauth_client_id", "query_tag", "client_session_keep_alive",