Skip to content

Commit

Permalink
Merge branch 'main' into add_release_internal_workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
VersusFacit authored Mar 26, 2024
2 parents 0df1cc3 + 1b5c165 commit 8a95469
Show file tree
Hide file tree
Showing 9 changed files with 102 additions and 12 deletions.
6 changes: 6 additions & 0 deletions .changes/unreleased/Fixes-20240318-203635.yaml
Original file line number Diff line number Diff line change
@@ -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"
6 changes: 6 additions & 0 deletions .changes/unreleased/Fixes-20240322-104553.yaml
Original file line number Diff line number Diff line change
@@ -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"
6 changes: 6 additions & 0 deletions .changes/unreleased/Under the Hood-20240227-010428.yaml
Original file line number Diff line number Diff line change
@@ -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"
1 change: 0 additions & 1 deletion dbt/adapters/snowflake/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ def _connection_keys(self):
"role",
"schema",
"authenticator",
"private_key_path",
"oauth_client_id",
"query_tag",
"client_session_keep_alive",
Expand Down
7 changes: 5 additions & 2 deletions dbt/adapters/snowflake/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 19 additions & 8 deletions dbt/adapters/snowflake/relation.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@
as (
{{ sql }}
)
;

{%- endmacro %}
43 changes: 43 additions & 0 deletions tests/functional/adapter/test_anonymous_usage_stats.py
Original file line number Diff line number Diff line change
@@ -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
17 changes: 17 additions & 0 deletions tests/unit/test_renamed_relations.py
Original file line number Diff line number Diff line change
@@ -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,
}
)

0 comments on commit 8a95469

Please sign in to comment.