Skip to content

Commit

Permalink
Merge pull request #55 from codeforkjeff/dbt-1-6-0-compat-2
Browse files Browse the repository at this point in the history
add minimum compatibility for 1.6.0
  • Loading branch information
codeforkjeff authored Jan 20, 2025
2 parents c72c439 + bde0e34 commit 6941d2b
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ RUN apt-get update && apt-get -y install git python3 python3-pip python3-venv sq
WORKDIR /opt/dbt-sqlite

RUN python3 -m pip install --upgrade pip \
&& python3 -m pip install pytest pytest-dotenv dbt-core~=1.5.0 dbt-tests-adapter~=1.5.0
&& python3 -m pip install pytest pytest-dotenv dbt-core~=1.6.0 dbt-tests-adapter~=1.6.0

RUN wget -q https://github.com/nalgeon/sqlean/releases/download/0.15.2/crypto.so
RUN wget -q https://github.com/nalgeon/sqlean/releases/download/0.15.2/math.so
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Use the right version. Starting with the release of dbt-core 1.0.0,
versions of dbt-sqlite are aligned to the same major+minor
[version](https://semver.org/) of dbt-core.

- versions 1.5.x of this adapter work with dbt-core 1.6.x
- versions 1.5.x of this adapter work with dbt-core 1.5.x
- versions 1.4.x of this adapter work with dbt-core 1.4.x
- versions 1.3.x of this adapter work with dbt-core 1.3.x
Expand Down
2 changes: 1 addition & 1 deletion dbt/adapters/sqlite/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version = '1.5.1'
version = '1.6.0'
35 changes: 30 additions & 5 deletions dbt/include/sqlite/macros/utils/dateadd.sql
Original file line number Diff line number Diff line change
@@ -1,8 +1,33 @@
{% macro sqlite__dateadd(datepart, interval, from_date_or_timestamp) %}
-- If provided a DATETIME, returns a DATETIME
-- If provided a DATE, returns a DATE

date(
{{ from_date_or_timestamp }},
"{{ interval }} {{ datepart }}"
)

CASE
-- Matches DATETIME type based on ISO-8601
WHEN {{ from_date_or_timestamp }} LIKE '%:%' OR ({{ from_date_or_timestamp }} LIKE '%T%' AND {{ from_date_or_timestamp }} LIKE '%Z%') THEN
CASE
WHEN LOWER({{ datepart }}) = 'second' THEN datetime({{ from_date_or_timestamp }}, '+' || {{ interval }} || ' seconds')
WHEN LOWER({{ datepart }}) = 'minute' THEN datetime({{ from_date_or_timestamp }}, '+' || {{ interval }} || ' minutes')
WHEN LOWER({{ datepart }}) = 'hour' THEN datetime({{ from_date_or_timestamp }}, '+' || {{ interval }} || ' hours')
WHEN LOWER({{ datepart }}) = 'day' THEN datetime({{ from_date_or_timestamp }}, '+' || {{ interval }} || ' days')
WHEN LOWER({{ datepart }}) = 'week' THEN datetime({{ from_date_or_timestamp }}, '+' || ({{ interval }} * 7) || ' days')
WHEN LOWER({{ datepart }}) = 'month' THEN datetime({{ from_date_or_timestamp }}, '+' || {{ interval }} || ' months')
WHEN LOWER({{ datepart }}) = 'quarter' THEN datetime({{ from_date_or_timestamp }}, '+' || ({{ interval }} * 3) || ' months')
WHEN LOWER({{ datepart }}) = 'year' THEN datetime({{ from_date_or_timestamp }}, '+' || {{ interval }} || ' years')
ELSE NULL
END
-- Matches DATE type based on ISO-8601
WHEN {{ from_date_or_timestamp }} LIKE '%-%' AND {{ from_date_or_timestamp }} NOT LIKE '%T%' AND {{ from_date_or_timestamp }} NOT LIKE '% %' THEN
CASE
WHEN LOWER({{ datepart }}) IN ('second', 'minute', 'hour') THEN date({{ from_date_or_timestamp }})
WHEN LOWER({{ datepart }}) = 'day' THEN date({{ from_date_or_timestamp }}, '+' || {{ interval }} || ' days')
WHEN LOWER({{ datepart }}) = 'week' THEN date({{ from_date_or_timestamp }}, '+' || ({{ interval }} * 7) || ' days')
WHEN LOWER({{ datepart }}) = 'month' THEN date({{ from_date_or_timestamp }}, '+' || {{ interval }} || ' months')
WHEN LOWER({{ datepart }}) = 'quarter' THEN date({{ from_date_or_timestamp }}, '+' || ({{ interval }} * 3) || ' months')
WHEN LOWER({{ datepart }}) = 'year' THEN date({{ from_date_or_timestamp }}, '+' || {{ interval }} || ' years')
ELSE NULL
END
ELSE
NULL
END
{% endmacro %}
2 changes: 1 addition & 1 deletion dbt/include/sqlite/macros/utils/timestamps.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{%- endmacro %}

{% macro sqlite__snapshot_string_as_time(timestamp) -%}
{# just return the string; SQLite doesn't have a timestamp data type per se #}
{# just return the string; SQLite doesn''t have a timestamp data type per se #}
{{ return("'" + timestamp|string + "'") }}
{%- endmacro %}

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def _get_plugin_version():
]
},
install_requires=[
"dbt-core~=1.5.0"
"dbt-core~=1.6.0"
],
classifiers=[
'Development Status :: 4 - Beta',
Expand Down
48 changes: 46 additions & 2 deletions tests/functional/adapter/utils/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
seeds__data_datediff_csv,
models__test_datediff_yml,
)
from dbt.tests.adapter.utils.fixture_dateadd import (
seeds__data_dateadd_csv,
models__test_dateadd_yml,
)
from dbt.tests.adapter.utils.test_any_value import BaseAnyValue
from dbt.tests.adapter.utils.test_array_append import BaseArrayAppend
from dbt.tests.adapter.utils.test_array_concat import BaseArrayConcat
Expand All @@ -29,6 +33,9 @@
from dbt.tests.adapter.utils.test_safe_cast import BaseSafeCast
from dbt.tests.adapter.utils.test_split_part import BaseSplitPart
from dbt.tests.adapter.utils.test_string_literal import BaseStringLiteral
from dbt.tests.adapter.utils.test_equals import BaseEquals
from dbt.tests.adapter.utils.test_null_compare import BaseMixedNullCompare, BaseNullCompare
from dbt.tests.adapter.utils.test_validate_sql import BaseValidateSqlMethod


class TestAnyValue(BaseAnyValue):
Expand Down Expand Up @@ -66,6 +73,32 @@ class TestConcat(BaseConcat):
class TestCurrentTimestampNaive(BaseCurrentTimestampNaive):
pass

class BaseDateAdd(BaseUtils):

models__test_dateadd_sql = """
with data as (
select * from {{ ref('data_dateadd') }}
)
select
{{ dateadd('datepart', 'interval_length', 'from_time') }} AS actual,
result as expected
from data
"""

@pytest.fixture(scope="class")
def seeds(self):
return {"data_dateadd.csv": seeds__data_dateadd_csv}

@pytest.fixture(scope="class")
def models(self):
return {
"test_dateadd.yml": models__test_dateadd_yml,
"test_dateadd.sql": self.interpolate_macro_namespace(
self.models__test_dateadd_sql, "dateadd"
),
}


class TestDateAdd(BaseDateAdd):
pass
Expand Down Expand Up @@ -179,10 +212,21 @@ class TestRight(BaseRight):
class TestSafeCast(BaseSafeCast):
pass


@pytest.mark.skip("TODO: implement split_part, either using sqlite>=3.8.3 for WITH RECURSIVE support, or possibly sooner using jinja and agate tables")
class TestSplitPart(BaseSplitPart):
pass


class TestStringLiteral(BaseStringLiteral):
pass

class TestEquals(BaseEquals):
pass

class TestMixedNullCompare(BaseMixedNullCompare):
pass

class TestNullCompare(BaseNullCompare):
pass

class TestValidateSqlMethod(BaseValidateSqlMethod):
pass

0 comments on commit 6941d2b

Please sign in to comment.