Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minimal changes to upgrade to dbt-core 1.6 #52

Merged
merged 4 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ install:
-p 50000:50000 \
-p 50002:50002 \
--privileged=true \
ibmcom/db2:11.5.7.0
icr.io/db2_community/db2:11.5.9.0
@docker logs -f dbt-db2 2>&1 | grep -m 1 '(*) Setup has completed.'
@docker exec \
-d \
Expand Down
1 change: 1 addition & 0 deletions dbt/adapters/ibmdb2/__version__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
version = "1.6.0"
3 changes: 3 additions & 0 deletions dbt/adapters/ibmdb2/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ def type(self):
def _connection_keys(self):
return ('host', 'database', 'schema', 'user', 'password', 'port', 'protocol', 'extra_connect_opts')

@property
def unique_field(self) -> str:
return self.host

class IBMDB2ConnectionManager(SQLConnectionManager):
TYPE = 'ibmdb2'
Expand Down
11 changes: 10 additions & 1 deletion dbt/include/ibmdb2/macros/utils/split_part.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
{% macro ibmdb2__split_part(string_text, delimiter_text, part_number) %}

REGEXP_SUBSTR('{{ string_text }}', '([^{{ delimiter_text }}]*){{ delimiter_text }}?', 1, {{ part_number }}, '', 1)
{% if part_number == 0 %}
{{ exceptions.raise_compiler_error("Invalid argument `part_number` must not be 0.") }}
{% elif part_number >= 1 %}
REGEXP_SUBSTR({{ string_text }}, '([^' || REGEXP_REPLACE({{ delimiter_text }}, '([\|.^$\\+?*\[\]])', '\\$1') || ']*)' || REGEXP_REPLACE({{ delimiter_text }}, '([\|.^$\\+?*\[\]])', '\\$1') || '?', 1, {{ part_number }}, '', 1)
{% else %}
CASE
WHEN REGEXP_COUNT({{ string_text }}, '([^' || REGEXP_REPLACE({{ delimiter_text }}, '([\|.^$\\+?*\[\]])', '\\$1') || ']*)' || REGEXP_REPLACE({{ delimiter_text }}, '([\|.^$\\+?*\[\]])', '\\$1') || '?') > 0 THEN REGEXP_SUBSTR({{ string_text }}, '([^' || REGEXP_REPLACE({{ delimiter_text }}, '([\|.^$\\+?*\[\]])', '\\$1') || ']*)' || REGEXP_REPLACE({{ delimiter_text }}, '([\|.^$\\+?*\[\]])', '\\$1') || '?', 1, REGEXP_COUNT({{ string_text }}, '([^' || REGEXP_REPLACE({{ delimiter_text }}, '([\|.^$\\+?*\[\]])', '\\$1') || ']*)' || REGEXP_REPLACE({{ delimiter_text }}, '([\|.^$\\+?*\[\]])', '\\$1') || '?') + {{ part_number }}, '', 1)
ELSE NULL
END
{% endif %}

{% endmacro %}
1,528 changes: 803 additions & 725 deletions poetry.lock

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "dbt-ibmdb2"
version = "1.4.2"
version = "1.6.0"
description = "The db2 adapter plugin for dbt (data build tool)"
authors = ["aurany <rasmus.nyberg@gmail.com>"]
license = "Apache Software License 2.0"
Expand All @@ -18,15 +18,15 @@ packages = [
]

[tool.poetry.dependencies]
python = ">=3.7.2"
dbt-core = "~1.4"
python = ">=3.8"
dbt-core = "~1.6"
ibm-db = "^3.1.0"

[tool.poetry.dev-dependencies]
pytest = "^7.1.2"
tox = "^3.25.1"
python-dotenv = "^0.20.0"
dbt-tests-adapter = "~1.4"
dbt-tests-adapter = "~1.6"

[build-system]
requires = ["poetry-core>=1.0.8"]
Expand Down
30 changes: 5 additions & 25 deletions tests/functional/adapter/test_macros.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@
from dbt.tests.adapter.utils.test_datediff import BaseDateDiff
from dbt.tests.adapter.utils.test_split_part import BaseSplitPart
from dbt.tests.adapter.utils.data_types.test_type_string import BaseTypeString
from dbt.tests.adapter.utils.fixture_dateadd import seeds__data_dateadd_csv
from dbt.tests.adapter.utils.fixture_datediff import models__test_datediff_yml
from dbt.tests.adapter.utils.fixture_split_part import seeds__data_split_part_csv

seeds__data_hash_csv = """input_1,output
ab,187EF4436122D1CC2F40DC2B92F0EBA0
a,0CC175B9C0F1B6A831C399E269772661
1,C4CA4238A0B923820DCC509A6F75849B
,D41D8CD98F00B204E9800998ECF8427E
EMPTY,D41D8CD98F00B204E9800998ECF8427E
"""

seeds__schema_hash_yml = """
Expand Down Expand Up @@ -84,12 +87,6 @@
from sysibm.sysdummy1
"""

seeds__data_split_part_csv = """parts,split_on,result_1,result_2,result_3
a|b|c,|,a,b,c
1|2|3,|,1,2,3
,|,,,
"""

seeds__schema_split_part_yml = """
version: 2
seeds:
Expand All @@ -102,14 +99,7 @@
result_1: varchar(10)
result_2: varchar(10)
result_3: varchar(10)
"""

seeds__data_dateadd_csv = """from_time,interval_length,datepart,result
2018-01-01 01:00:00,1,day,2018-01-02 01:00:00
2018-01-01 01:00:00,1,month,2018-02-01 01:00:00
2018-01-01 01:00:00,1,year,2019-01-01 01:00:00
2018-01-01 01:00:00,1,hour,2018-01-01 02:00:00
,1,day,
result_4: varchar(10)
"""

seeds__schema_dateadd_yml = """
Expand Down Expand Up @@ -198,16 +188,6 @@
union all select {{ datediff("'1999-01-01 00:00:00.000000'", "'2000-01-01 00:00:00.000000'", "year") }} as actual, 1 as expected from sysibm.sysdummy1
"""

models__test_datediff_yml = """
version: 2
models:
- name: test_datediff
tests:
- assert_equal:
actual: actual
expected: expected
"""

class TestHashIBMDB2(BaseHash):
@pytest.fixture(scope="class")
def seeds(self):
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tox]
isolated_build = true
envlist = python3.7,python3.8,python3.9,python3.10,python3.11
envlist = python3.8,python3.9,python3.10,python3.11

[testenv]
whitelist_externals = pytest
Expand Down