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 support for dbt core 1.4 #345

Closed
wants to merge 9 commits into from
Closed
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 .github/workflows/integration-tests-azure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
if: contains(github.event.pull_request.labels.*.name, 'safe to test') || github.ref_name == 'master' || github.ref_name == 'azure-testing'
strategy:
matrix:
python_version: ["3.7", "3.8", "3.9", "3.10"]
python_version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
profile: ["ci_azure_cli", "ci_azure_auto", "ci_azure_environment", "ci_azure_basic"]
msodbc_version: ["17", "18"]
max-parallel: 1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/integration-tests-sqlserver.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
name: Integration tests on SQL Server
strategy:
matrix:
python_version: ["3.7", "3.8", "3.9", "3.10"]
python_version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
msodbc_version: ["17", "18"]
sqlserver_version: ["2017", "2019", "2022"]
runs-on: ubuntu-latest
Expand Down
8 changes: 7 additions & 1 deletion .github/workflows/publish-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,18 @@ on: # yamllint disable-line rule:truthy
- '.github/workflows/publish-docker.yml'
branches:
- 'master'
pull_request:
paths:
- 'devops/**'
- '.github/workflows/publish-docker.yml'
branches:
- 'master'

jobs:
publish-docker-client:
strategy:
matrix:
python_version: ["3.7", "3.8", "3.9", "3.10"]
python_version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
docker_target: ["msodbc17", "msodbc18"]
runs-on: ubuntu-latest
permissions:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
name: Unit tests
strategy:
matrix:
python_version: ["3.7", "3.8", "3.9", "3.10"]
python_version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
runs-on: ubuntu-latest
permissions:
contents: read
Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Changelog

### v1.4.0

#### Features

* Support for [dbt-core 1.4](https://github.com/dbt-labs/dbt-core/releases/tag/v1.4.1)
* [Incremental predicates](https://docs.getdbt.com/docs/build/incremental-models#about-incremental_predicates) are currently not supported in this adapter
* Add support for Python 3.11
* Replace deprecated exception functions
* Consolidate timestamp macros

### v1.3.0

#### Features
Expand Down
2 changes: 1 addition & 1 deletion dbt/adapters/sqlserver/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version = "1.3.1"
version = "1.4.0"
6 changes: 3 additions & 3 deletions dbt/adapters/sqlserver/sql_server_connection_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,19 +250,19 @@ def exception_handler(self, sql):
except pyodbc.Error:
logger.debug("Failed to release connection!")

raise dbt.exceptions.DatabaseException(str(e).strip()) from e
raise dbt.exceptions.DbtDatabaseError(str(e).strip()) from e

except Exception as e:
logger.debug(f"Error running SQL: {sql}")
logger.debug("Rolling back transaction.")
self.release()
if isinstance(e, dbt.exceptions.RuntimeException):
if isinstance(e, dbt.exceptions.DbtRuntimeError):
# during a sql query, an internal to dbt exception was raised.
# this sounds a lot like a signal handler and probably has
# useful information, so raise it without modification.
raise

raise dbt.exceptions.RuntimeException(e)
raise dbt.exceptions.DbtRuntimeError(e)

@classmethod
def open(cls, connection: Connection) -> Connection:
Expand Down
3 changes: 0 additions & 3 deletions dbt/include/sqlserver/macros/adapters/freshness.sql

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
{{ default__get_merge_sql(target, source, unique_key, dest_columns, predicates) }};
{% endmacro %}

{% macro sqlserver__get_delete_insert_merge_sql(target, source, unique_key, dest_columns) %}
{% macro sqlserver__get_delete_insert_merge_sql(target, source, unique_key, dest_columns, incremental_predicates) %}
{% if incremental_predicates %}
{{ exceptions.raise_not_implemented('incremental_predicates are not implemented in dbt-sqlserver') }}
{% endif %}

{%- set dest_cols_csv = get_quoted_csv(dest_columns | map(attribute="name")) -%}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,3 @@
coalesce(cast({{ arg }} as varchar(max)), '') {% if not loop.last %} + '|' + {% endif %}
{% endfor %}), 2)
{% endmacro %}

{% macro sqlserver__snapshot_string_as_time(timestamp) -%}
{%- set result = "CONVERT(DATETIME2, '" ~ timestamp ~ "')" -%}
{{ return(result) }}
{%- endmacro %}
8 changes: 8 additions & 0 deletions dbt/include/sqlserver/macros/utils/timestamps.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{% macro sqlserver__current_timestamp() -%}
SYSDATETIME()
{%- endmacro %}

{% macro sqlserver__snapshot_string_as_time(timestamp) -%}
{%- set result = "CONVERT(DATETIME2, '" ~ timestamp ~ "')" -%}
{{ return(result) }}
{%- endmacro %}
3 changes: 2 additions & 1 deletion dev_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ twine==4.0.2
wheel==0.38.4
pre-commit==2.20.0
pytest-dotenv==0.5.2
dbt-tests-adapter==1.3.1
pytz==2023.3
dbt-tests-adapter~=1.4.5
-e .
9 changes: 5 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

package_name = "dbt-sqlserver"
authors_list = ["Mikael Ene", "Anders Swanson", "Sam Debruyn", "Cor Zuurmond"]
dbt_version = "1.3"
dbt_version = "1.4"
description = """A Microsoft SQL Server adapter plugin for dbt"""

this_directory = os.path.abspath(os.path.dirname(__file__))
Expand Down Expand Up @@ -66,9 +66,9 @@ def run(self):
packages=find_namespace_packages(include=["dbt", "dbt.*"]),
include_package_data=True,
install_requires=[
"dbt-core>=1.3.0",
"pyodbc>=4.0.32,!=4.0.34",
"azure-identity>=1.10.0",
"dbt-core~=1.4.5",
"pyodbc~=4.0.35,!=4.0.36,!=4.0.37",
"azure-identity>=1.12.0",
],
cmdclass={
"verify": VerifyVersionCommand,
Expand All @@ -83,5 +83,6 @@ def run(self):
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
],
)
18 changes: 18 additions & 0 deletions tests/functional/adapter/test_timestamps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import pytest
from dbt.tests.adapter.utils.test_timestamps import BaseCurrentTimestamps


class TestCurrentTimestampSQLServer(BaseCurrentTimestamps):
@pytest.fixture(scope="class")
def models(self):
return {
"get_current_timestamp.sql": 'select {{ current_timestamp() }} as "current_timestamp"'
}

@pytest.fixture(scope="class")
def expected_schema(self):
return {"current_timestamp": "datetime2"}

@pytest.fixture(scope="class")
def expected_sql(self):
return '''select SYSDATETIME() as "current_timestamp"'''