Skip to content

Commit

Permalink
Migrate to dbt-common and dbt-adapters package (#885)
Browse files Browse the repository at this point in the history
* update RELEASE_BRANCH env

* create draft pr to track work

* initial migration work

* get tests_connections unit test passing

* update model_node refs to relation_config, update _macro_manifest_lazy ref in unit test

* update new_config ping in dynamic_table configuration_changes macro

* minor changes to imports

* minor changes, revert dev-requirements pointer

* revert runtime_config call

* fix list_relations_without_caching

* change up test input for schema_relation

* update snowflake__get_paginated_relations_array macro schema_relation call

* add changelog

* prepare draft pr for dbt-common name change in core

* change pointer and add ref to dbt-common in setup.py

* change pointer back to main post merge in core

* adjust one nit import and ref

* add dbt-adapters and changelog

* add dbt-adapters

* migrate to dbt-adapters package

* slight change to dbt-adapter pointer, and slight change in fixture ref for dbt_test on test_column_types

* swap dbt-adapters ref in setup.py

* try and pin common and adapters

* update fixtures

* update dbt-adapters ref

---------

Co-authored-by: Colin <[email protected]>
  • Loading branch information
McKnight-42 and colin-rogers-dbt authored Jan 18, 2024
1 parent a43f86b commit 4b2d938
Show file tree
Hide file tree
Showing 12 changed files with 36 additions and 29 deletions.
6 changes: 6 additions & 0 deletions .changes/unreleased/Under the Hood-20240117-112026.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Under the Hood
body: Migrate to dbt-common and dbt-adapters package
time: 2024-01-17T11:20:26.713584-06:00
custom:
Author: McKnight-42
Issue: "890"
2 changes: 1 addition & 1 deletion dbt/adapters/snowflake/column.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from dataclasses import dataclass

from dbt.adapters.base.column import Column
from dbt.common.exceptions import DbtRuntimeError
from dbt_common.exceptions import DbtRuntimeError


@dataclass
Expand Down
15 changes: 7 additions & 8 deletions dbt/adapters/snowflake/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from typing import Optional, Tuple, Union, Any, List

import agate
import dbt.common.clients.agate_helper
from dbt_common.clients.agate_helper import empty_table

from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import serialization
Expand All @@ -32,20 +32,19 @@
BindUploadError,
)

from dbt.common.exceptions import (
from dbt_common.exceptions import (
DbtInternalError,
DbtRuntimeError,
DbtConfigError,
)
from dbt.common.exceptions import DbtDatabaseError
from dbt.adapters.base import Credentials # type: ignore
from dbt_common.exceptions import DbtDatabaseError
from dbt.adapters.exceptions.connection import FailedToConnectError
from dbt.adapters.contracts.connection import AdapterResponse, Connection
from dbt.adapters.contracts.connection import AdapterResponse, Connection, Credentials
from dbt.adapters.sql import SQLConnectionManager # type: ignore
from dbt.adapters.events.logging import AdapterLogger # type: ignore
from dbt.common.events.functions import warn_or_error
from dbt_common.events.functions import warn_or_error
from dbt.adapters.events.types import AdapterEventWarning
from dbt.common.ui import line_wrap_message, warning_tag
from dbt_common.ui import line_wrap_message, warning_tag


logger = AdapterLogger("Snowflake")
Expand Down Expand Up @@ -476,7 +475,7 @@ def execute(
if fetch:
table = self.get_result_from_cursor(cursor, limit)
else:
table = dbt.common.clients.agate_helper.empty_table()
table = empty_table()
return response, table

def add_standard_query(self, sql: str, **kwargs) -> Tuple[Connection, Any]:
Expand Down
6 changes: 3 additions & 3 deletions dbt/adapters/snowflake/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
from dbt.adapters.snowflake import SnowflakeConnectionManager
from dbt.adapters.snowflake import SnowflakeRelation
from dbt.adapters.snowflake import SnowflakeColumn
from dbt.common.contracts.constraints import ConstraintType
from dbt.common.exceptions import CompilationError, DbtDatabaseError, DbtRuntimeError
from dbt.common.utils import filter_null_values
from dbt_common.contracts.constraints import ConstraintType
from dbt_common.exceptions import CompilationError, DbtDatabaseError, DbtRuntimeError
from dbt_common.utils import filter_null_values


@dataclass
Expand Down
2 changes: 1 addition & 1 deletion dbt/adapters/snowflake/relation_configs/policies.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from dataclasses import dataclass

from dbt.adapters.base.relation import Policy
from dbt.common.dataclass_schema import StrEnum
from dbt_common.dataclass_schema import StrEnum


class SnowflakeRelationType(StrEnum):
Expand Down
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ def _get_dbt_core_version():
include_package_data=True,
install_requires=[
"dbt-core~={}".format(dbt_core_version),
"dbt-common~=0.1.0",
"dbt-adapters~=0.1.0a2",
"snowflake-connector-python[secure-local-storage]~=3.0",
# installed via dbt-core but referenced directly; don't pin to avoid version conflicts with dbt-core
"agate",
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/adapter/column_types/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
version: 2
models:
- name: model
tests:
data_tests:
- is_type:
column_map:
smallint_col: ['numeric', 'number', 'not string', 'not float', 'not integer']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import pytest

from dbt.common.contracts.config.materialization import OnConfigurationChangeOption
from dbt_common.contracts.config.materialization import OnConfigurationChangeOption
from dbt.tests.util import (
assert_message_in_logs,
get_model_file,
Expand Down
20 changes: 10 additions & 10 deletions tests/functional/adapter/simple_seed/test_simple_seed_override.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,46 +8,46 @@
- name: seed_enabled
columns:
- name: birthday
tests:
data_tests:
- column_type:
type: character varying(16777216)
- name: seed_id
tests:
data_tests:
- column_type:
type: FLOAT
- name: seed_tricky
columns:
- name: seed_id
tests:
data_tests:
- column_type:
type: NUMBER(38,0)
- name: seed_id_str
tests:
data_tests:
- column_type:
type: character varying(16777216)
- name: a_bool
tests:
data_tests:
- column_type:
type: BOOLEAN
- name: looks_like_a_bool
tests:
data_tests:
- column_type:
type: character varying(16777216)
- name: a_date
tests:
data_tests:
- column_type:
type: TIMESTAMP_NTZ
- name: looks_like_a_date
tests:
data_tests:
- column_type:
type: character varying(16777216)
- name: relative
tests:
data_tests:
- column_type:
type: character varying(16777216)
- name: weekday
tests:
data_tests:
- column_type:
type: character varying(16777216)
""".lstrip()
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/query_tag/test_query_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
- name: view_model_query_tag
columns:
- name: id
tests:
data_tests:
- unique
"""
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_snowflake_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from dbt.context.manifest 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 dbt_common.clients import agate_helper
from snowflake import connector as snowflake_connector

from .utils import (
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import agate
import pytest
from dbt.common.dataclass_schema import ValidationError
from dbt_common.dataclass_schema import ValidationError
from dbt.config.project import PartialProject


Expand Down Expand Up @@ -230,7 +230,7 @@ def assert_fails_validation(dct, cls):

class TestAdapterConversions(TestCase):
def _get_tester_for(self, column_type):
from dbt.common.clients import agate_helper
from dbt_common.clients import agate_helper

if column_type is agate.TimeDelta: # dbt never makes this!
return agate.TimeDelta()
Expand Down

0 comments on commit 4b2d938

Please sign in to comment.