Skip to content

Commit

Permalink
Merge branch 'main' into ADAP-209/update_iceberg_docs_note
Browse files Browse the repository at this point in the history
  • Loading branch information
VersusFacit committed Nov 19, 2024
2 parents 43d73d5 + a16654b commit 4f49871
Show file tree
Hide file tree
Showing 10 changed files with 197 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .changes/unreleased/Under the Hood-20241016-035544.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Under the Hood
body: Add telemetry function
time: 2024-10-16T03:55:44.144174-07:00
custom:
Author: versusfacit
Issue: "301"
4 changes: 2 additions & 2 deletions .github/scripts/integration-test-matrix.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ module.exports = ({ context }) => {

if (labels.includes("test macos") || testAllLabel) {
include.push({
os: "macos-12",
os: "macos-14",
adapter,
"python-version": pythonVersion,
});
Expand Down Expand Up @@ -78,7 +78,7 @@ module.exports = ({ context }) => {
// additionally include runs for all adapters, on macos and windows,
// but only for the default python version
for (const adapter of supportedAdapters) {
for (const operatingSystem of ["windows-latest", "macos-12"]) {
for (const operatingSystem of ["windows-latest", "macos-14"]) {
include.push({
os: operatingSystem,
adapter: adapter,
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-12, windows-latest]
os: [ubuntu-latest, macos-14, windows-latest]
python-version: ['3.9', '3.10', '3.11', '3.12']
dist-type: ['whl', 'gz']

Expand Down
17 changes: 17 additions & 0 deletions dbt/adapters/snowflake/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from dbt.adapters.base.impl import AdapterConfig, ConstraintSupport
from dbt.adapters.base.meta import available
from dbt.adapters.capability import CapabilityDict, CapabilitySupport, Support, Capability
from dbt.adapters.contracts.relation import RelationConfig
from dbt.adapters.sql import SQLAdapter
from dbt.adapters.sql.impl import (
LIST_SCHEMAS_MACRO_NAME,
Expand All @@ -25,6 +26,7 @@
SnowflakeRelationType,
TableFormat,
)

from dbt.adapters.snowflake import SnowflakeColumn
from dbt.adapters.snowflake import SnowflakeConnectionManager
from dbt.adapters.snowflake import SnowflakeRelation
Expand Down Expand Up @@ -419,3 +421,18 @@ def valid_incremental_strategies(self):
def debug_query(self):
"""Override for DebugTask method"""
self.execute("select 1 as id")

@classmethod
def _get_adapter_specific_run_info(cls, config: RelationConfig) -> Dict[str, Any]:
table_format: Optional[str] = None
if (
config
and hasattr(config, "_extra")
and (relation_format := config._extra.get("table_format"))
):
table_format = relation_format

return {
"adapter_type": "snowflake",
"table_format": table_format,
}
Empty file.
90 changes: 90 additions & 0 deletions tests/functional/generic_test_tests/_files.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
SCHEMA__CONTROL = """
version: 2
models:
- name: colors
columns:
- name: color
data_tests:
- not_null
"""


SCHEMA__EXPLICIT_WAREHOUSE = """
version: 2
models:
- name: colors
columns:
- name: color
data_tests:
- not_null:
config:
snowflake_warehouse: DBT_TESTING_ALT
"""


SCHEMA__NOT_NULL = """
version: 2
models:
- name: facts
columns:
- name: value
data_tests:
- not_null:
config:
snowflake_warehouse: DBT_TESTING_ALT
"""


SCHEMA__RELATIONSHIPS = """
version: 2
models:
- name: facts
columns:
- name: color
data_tests:
- relationships:
to: ref('my_colors')
field: color
config:
snowflake_warehouse: DBT_TESTING_ALT
"""


SCHEMA__ACCEPTED_VALUES = """
version: 2
models:
- name: colors
columns:
- name: color
data_tests:
- accepted_values:
values: ['blue', 'red', 'green']
config:
snowflake_warehouse: DBT_TESTING_ALT
"""


SEED__COLORS = """
color
blue
green
red
yellow
""".strip()


# record 10 is missing a value
# record 7 has a color that's not on COLORS
SEED__FACTS = """
id,color,value
1,blue,10
2,red,20
3,green,30
4,yellow,40
5,blue,50
6,red,60
7,orange,70
8,green,80
9,yellow,90
10,blue,
""".strip()
Empty file.
Empty file.
54 changes: 54 additions & 0 deletions tests/functional/generic_test_tests/test_generic_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import pytest

from dbt.tests.util import run_dbt, run_dbt_and_capture

from tests.functional.generic_test_tests import _files


class TestWarehouseConfig:

@pytest.fixture(scope="class")
def seeds(self):
return {
"colors.csv": _files.SEED__COLORS,
"facts.csv": _files.SEED__FACTS,
}

@pytest.fixture(scope="class", autouse=True)
def setup(self, project):
run_dbt(["seed"])
run_dbt(["run"])
yield


class TestWarehouseConfigControl(TestWarehouseConfig):

@pytest.fixture(scope="class")
def models(self):
return {"schema.yml": _files.SCHEMA__CONTROL}

def test_expected_warehouse(self, project):
results, logs = run_dbt_and_capture(["test"])
assert len(results) == 1


class TestWarehouseConfigExplicitWarehouse(TestWarehouseConfig):

@pytest.fixture(scope="class")
def models(self):
return {"schema.yml": _files.SCHEMA__EXPLICIT_WAREHOUSE}

def test_expected_warehouse(self, project):
_, logs = run_dbt_and_capture(["test", "--log-level", "debug"])
assert "use warehouse " in logs


class TestWarehouseConfigNotNull(TestWarehouseConfig):

@pytest.fixture(scope="class")
def models(self):
return {"schema.yml": _files.SCHEMA__NOT_NULL}

def test_expected_warehouse(self, project):
_, logs = run_dbt_and_capture(["test", "--log-level", "debug"], expect_pass=False)
assert "use warehouse " in logs
27 changes: 27 additions & 0 deletions tests/unit/test_adapter_telemetry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from unittest import mock

import dbt.adapters.snowflake.__version__

from dbt.adapters.snowflake.impl import SnowflakeAdapter
from dbt.adapters.base.relation import AdapterTrackingRelationInfo


def test_telemetry_with_snowflake_details():
mock_model_config = mock.MagicMock()
mock_model_config._extra = mock.MagicMock()
mock_model_config._extra = {
"adapter_type": "snowflake",
"table_format": "iceberg",
}

res = SnowflakeAdapter.get_adapter_run_info(mock_model_config)

assert res.adapter_name == "snowflake"
assert res.base_adapter_version == dbt.adapters.__about__.version
assert res.adapter_version == dbt.adapters.snowflake.__version__.version
assert res.model_adapter_details == {
"adapter_type": "snowflake",
"table_format": "iceberg",
}

assert type(res) is AdapterTrackingRelationInfo

0 comments on commit 4f49871

Please sign in to comment.