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

add minimum compatibility for 1.6.0 #55

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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 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.0'
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 }},
"{{ datepart }} {{ 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
Loading