Skip to content

Commit

Permalink
Merge pull request #280 from duckdb/jwills_170_prep
Browse files Browse the repository at this point in the history
Prep work for dbt-core 1.7.0
  • Loading branch information
jwills authored Nov 3, 2023
2 parents 2ea2235 + fae7aa7 commit 90eeb4a
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 33 deletions.
2 changes: 1 addition & 1 deletion dbt/adapters/duckdb/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version = "1.6.2"
version = "1.7.0"
3 changes: 2 additions & 1 deletion dbt/include/duckdb/macros/seed.sql
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
{% macro duckdb__load_csv_rows(model, agate_table) %}
{% if config.get('fast', true) %}
{% set seed_file_path = adapter.get_seed_file_path(model) %}
{% set delimiter = config.get('delimiter', ',') %}
{% set sql %}
COPY {{ this.render() }} FROM '{{ seed_file_path }}' (FORMAT CSV, HEADER TRUE)
COPY {{ this.render() }} FROM '{{ seed_file_path }}' (FORMAT CSV, HEADER TRUE, DELIMITER '{{ delimiter }}')
{% endset %}
{% do adapter.add_query(sql, abridge_sql_log=True) %}
{{ return(sql) }}
Expand Down
2 changes: 1 addition & 1 deletion dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# git+https://github.com/dbt-labs/dbt-core.git#egg=dbt-core&subdirectory=core
# git+https://github.com/dbt-labs/dbt-core.git#egg=dbt-tests-adapter&subdirectory=tests/adapter

dbt-tests-adapter==1.6.6
dbt-tests-adapter==1.7.0

boto3
mypy-boto3-glue
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def _dbt_duckdb_version():
packages=find_namespace_packages(include=["dbt", "dbt.*"]),
include_package_data=True,
install_requires=[
"dbt-core~=1.6.0",
"dbt-core~=1.7.0",
"duckdb>=0.7.0",
],
extras_require={
Expand Down
36 changes: 35 additions & 1 deletion tests/functional/adapter/simple_seed/test_fast_seed.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pytest

from dbt.tests.adapter.simple_seed.test_seed import SeedTestBase
from dbt.tests.adapter.simple_seed.test_seed import SeedUniqueDelimiterTestBase
from dbt.tests.util import (
run_dbt,
)
Expand All @@ -14,4 +15,37 @@ def project_config_update(self):

def test_simple_seed_fast(self, project):
self._build_relations_for_test(project)
self._check_relation_end_state(run_result=run_dbt(["seed"]), project=project, exists=True)
self._check_relation_end_state(run_result=run_dbt(["seed"]), project=project, exists=True)


class TestSeedWithUniqueDelimiter(SeedUniqueDelimiterTestBase):
def test_seed_with_unique_delimiter(self, project):
"""Testing correct run of seeds with a unique delimiter (pipe in this case)"""
self._build_relations_for_test(project)
self._check_relation_end_state(run_result=run_dbt(["seed"]), project=project, exists=True)


class TestSeedWithWrongDelimiter(SeedUniqueDelimiterTestBase):
@pytest.fixture(scope="class")
def project_config_update(self):
return {
"seeds": {"quote_columns": False, "delimiter": ";"},
}

def test_seed_with_wrong_delimiter(self, project):
"""Testing failure of running dbt seed with a wrongly configured delimiter"""
seed_result = run_dbt(["seed"], expect_pass=False)
assert "syntax error" in seed_result.results[0].message.lower()


class TestSeedWithEmptyDelimiter(SeedUniqueDelimiterTestBase):
@pytest.fixture(scope="class")
def project_config_update(self):
return {
"seeds": {"quote_columns": False, "delimiter": ""},
}

def test_seed_with_empty_delimiter(self, project):
"""Testing failure of running dbt seed with an empty configured delimiter value"""
seed_result = run_dbt(["seed"], expect_pass=False)
assert "compilation error" in seed_result.results[0].message.lower()
25 changes: 25 additions & 0 deletions tests/functional/adapter/utils/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@
from dbt.tests.adapter.utils.test_date_trunc import BaseDateTrunc
from dbt.tests.adapter.utils.test_dateadd import BaseDateAdd
from dbt.tests.adapter.utils.test_datediff import BaseDateDiff
from dbt.tests.adapter.utils.test_date_spine import BaseDateSpine
from dbt.tests.adapter.utils.test_escape_single_quotes import (
BaseEscapeSingleQuotesQuote,
)
from dbt.tests.adapter.utils.test_except import BaseExcept
from dbt.tests.adapter.utils.test_generate_series import BaseGenerateSeries
from dbt.tests.adapter.utils.test_get_intervals_between import BaseGetIntervalsBetween
from dbt.tests.adapter.utils.test_get_powers_of_two import BaseGetPowersOfTwo
from dbt.tests.adapter.utils.test_hash import BaseHash
from dbt.tests.adapter.utils.test_intersect import BaseIntersect
from dbt.tests.adapter.utils.test_last_day import BaseLastDay
Expand Down Expand Up @@ -52,6 +56,12 @@ class TestDateDiff(BaseDateDiff):
pass


# Skipping this b/c the upstream utils test
# is irritatingly adapter-specific at the moment
@pytest.mark.skip
class TestDateSpine(BaseDateSpine):
pass

class TestDateTrunc(BaseDateTrunc):
pass

Expand All @@ -60,6 +70,21 @@ class TestEscapeSingleQuotes(BaseEscapeSingleQuotesQuote):
pass


class TestGenerateSeries(BaseGenerateSeries):
pass


# Skipping this b/c the upstream utils test
# is irritatingly adapter-specific at the moment
@pytest.mark.skip
class TestGetIntervalsBetween(BaseGetIntervalsBetween):
pass


class TestGetPowersOfTwo(BaseGetPowersOfTwo):
pass


class TestExcept(BaseExcept):
pass

Expand Down
28 changes: 0 additions & 28 deletions tests/unit/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from unittest import TestCase, mock

from dbt.config.project import PartialProject
from hologram import ValidationError


def normalize(path):
Expand Down Expand Up @@ -121,33 +120,6 @@ def inject_adapter(value, plugin):
FACTORY.adapters[key] = value


class ContractTestCase(TestCase):
ContractType = None

def setUp(self):
self.maxDiff = None
super().setUp()

def assert_to_dict(self, obj, dct):
self.assertEqual(obj.to_dict(), dct)

def assert_from_dict(self, obj, dct, cls=None):
if cls is None:
cls = self.ContractType
self.assertEqual(cls.from_dict(dct), obj)

def assert_symmetric(self, obj, dct, cls=None):
self.assert_to_dict(obj, dct)
self.assert_from_dict(obj, dct, cls)

def assert_fails_validation(self, dct, cls=None):
if cls is None:
cls = self.ContractType

with self.assertRaises(ValidationError):
cls.from_dict(dct)


def generate_name_macros(package):
from dbt.contracts.graph.parsed import ParsedMacro
from dbt.node_types import NodeType
Expand Down

0 comments on commit 90eeb4a

Please sign in to comment.