Skip to content

Commit

Permalink
Migrate to dbt-common and dbt-adapters package
Browse files Browse the repository at this point in the history
  • Loading branch information
damian3031 committed Mar 12, 2024
1 parent 4a8010b commit e152e3f
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 31 deletions.
7 changes: 7 additions & 0 deletions .changes/unreleased/Under the Hood-20240312-132326.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
kind: Under the Hood
body: Migrate to dbt-common and dbt-adapters package
time: 2024-03-12T13:23:26.028488+01:00
custom:
Author: damian3031
Issue: "387"
PR: "390"
2 changes: 1 addition & 1 deletion dbt/adapters/trino/column.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from typing import ClassVar, Dict

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

# Taken from the MAX_LENGTH variable in
# https://github.com/trinodb/trino/blob/master/core/trino-spi/src/main/java/io/trino/spi/type/VarcharType.java
Expand Down
10 changes: 5 additions & 5 deletions dbt/adapters/trino/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@

import sqlparse
import trino
from dbt.adapters.base import Credentials
from dbt.adapters.contracts.connection import AdapterResponse, Credentials
from dbt.adapters.events.logging import AdapterLogger
from dbt.adapters.exceptions.connection import FailedToConnectError
from dbt.adapters.sql import SQLConnectionManager
from dbt.contracts.connection import AdapterResponse
from dbt.events import AdapterLogger
from dbt.exceptions import DbtDatabaseError, DbtRuntimeError, FailedToConnectError
from dbt.helper_types import Port
from dbt_common.exceptions import DbtDatabaseError, DbtRuntimeError
from dbt_common.helper_types import Port
from trino.transaction import IsolationLevel

from dbt.adapters.trino.__version__ import version
Expand Down
4 changes: 2 additions & 2 deletions dbt/adapters/trino/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
Support,
)
from dbt.adapters.sql import SQLAdapter
from dbt.contracts.graph.nodes import ConstraintType
from dbt.exceptions import DbtDatabaseError
from dbt_common.contracts.constraints import ConstraintType
from dbt_common.exceptions import DbtDatabaseError

from dbt.adapters.trino import TrinoColumn, TrinoConnectionManager, TrinoRelation

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

from dbt.adapters.base.relation import BaseRelation, Policy
from dbt.contracts.relation import ComponentName
from dbt.adapters.contracts.relation import ComponentName


@dataclass(frozen=True, eq=False, repr=False)
Expand Down
3 changes: 2 additions & 1 deletion dev_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
dbt-tests-adapter~=1.7.9
dbt-core~=1.8.0b1
dbt-tests-adapter~=1.8.0b1
mypy==1.8.0 # patch updates have historically introduced breaking changes
pre-commit~=3.6
pytest~=7.4
Expand Down
12 changes: 2 additions & 10 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,8 @@ def _dbt_trino_version():
return trino_version


# require a compatible minor version (~=), prerelease if this is a prerelease
def _get_dbt_core_version():
parts = _get_plugin_version_dict()
minor = "{major}.{minor}.0".format(**parts)
pre = parts["prekind"] + "1" if parts["prekind"] else ""
return f"{minor}{pre}"


package_version = _dbt_trino_version()
description = """The trino adapter plugin for dbt (data build tool)"""
dbt_version = _get_dbt_core_version()

setup(
name=package_name,
Expand All @@ -85,7 +76,8 @@ def _get_dbt_core_version():
]
},
install_requires=[
"dbt-core~={}".format(dbt_version),
"dbt-common>=1.0.0b1,<2.0",
"dbt-adapters>=1.0.0b1,<2.0",
"trino~=0.326",
],
zip_safe=False,
Expand Down
5 changes: 2 additions & 3 deletions tests/functional/adapter/show/test_show.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import pytest
from dbt.exceptions import DbtRuntimeError
from dbt.exceptions import Exception as DbtException
from dbt.tests.util import run_dbt, run_dbt_and_capture
from dbt_common.exceptions import DbtBaseException, DbtRuntimeError

from tests.functional.adapter.show.fixtures import (
models__ephemeral_model,
Expand Down Expand Up @@ -73,7 +72,7 @@ def test_inline_pass(self, project):
assert "sample_bool" in log_output

def test_inline_fail(self, project):
with pytest.raises(DbtException, match="Error parsing inline query"):
with pytest.raises(DbtBaseException, match="Error parsing inline query"):
run_dbt(["show", "--inline", "select * from {{ ref('third_model') }}"])

def test_inline_fail_database_error(self, project):
Expand Down
14 changes: 7 additions & 7 deletions tests/unit/test_adapter.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import string
import unittest
from multiprocessing import get_context
from unittest import TestCase
from unittest.mock import MagicMock, Mock, patch

import agate
import dbt.flags as flags
import trino
from dbt.clients import agate_helper
from dbt.exceptions import DbtDatabaseError, DbtRuntimeError, FailedToConnectError
from dbt.adapters.exceptions.connection import FailedToConnectError
from dbt_common.clients import agate_helper
from dbt_common.exceptions import DbtDatabaseError, DbtRuntimeError

from dbt.adapters.trino import TrinoAdapter
from dbt.adapters.trino.column import TRINO_VARCHAR_MAX_LENGTH, TrinoColumn
Expand Down Expand Up @@ -70,7 +72,7 @@ def setUp(self):

@property
def adapter(self):
self._adapter = TrinoAdapter(self.config)
self._adapter = TrinoAdapter(self.config, get_context("spawn"))
return self._adapter

def test_acquire_connection(self):
Expand Down Expand Up @@ -144,7 +146,7 @@ def acquire_connection_with_profile(self, profile):

config = config_from_parts_or_dicts(project_cfg, profile_cfg)

return TrinoAdapter(config).acquire_connection("dummy")
return TrinoAdapter(config, get_context("spawn")).acquire_connection("dummy")

def assert_default_connection_credentials(self, credentials):
self.assertEqual(credentials.type, "trino")
Expand Down Expand Up @@ -447,7 +449,7 @@ def setup_profile(self, credentials):
}

config = config_from_parts_or_dicts(project_cfg, profile_cfg)
adapter = TrinoAdapter(config)
adapter = TrinoAdapter(config, get_context("spawn"))
connection = adapter.acquire_connection("dummy")
return connection

Expand Down Expand Up @@ -501,8 +503,6 @@ def test_true(self):

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

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

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from unittest import TestCase, mock

from dbt.config.project import PartialProject
from dbt.dataclass_schema import ValidationError
from dbt_common.dataclass_schema import ValidationError


def normalize(path):
Expand Down

0 comments on commit e152e3f

Please sign in to comment.