Skip to content

DBT 1.8 and test coverage updates #513

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

Merged
merged 8 commits into from
Aug 23, 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
3 changes: 2 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"features": {
"ghcr.io/devcontainers/features/docker-in-docker:2": {}
},
"postStartCommand": "sudo bash .devcontainer/setup_odbc.sh && bash .devcontainer/install_pyenv.sh && bash .devcontainer/setup_env.sh",
"forwardPorts": [1433],
"postStartCommand": "/bin/bash ./.devcontainer/setup_odbc.sh & /bin/bash ./.devcontainer/setup_env.sh",
"containerEnv": {
"SQLSERVER_TEST_DRIVER": "ODBC Driver 18 for SQL Server",
"SQLSERVER_TEST_HOST": "127.0.0.1",
Expand Down
8 changes: 3 additions & 5 deletions .devcontainer/setup_env.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
cp test.env.sample test.env

pyenv install 3.10.7
pyenv virtualenv 3.10.7 dbt-sqlserver
pyenv activate dbt-sqlserver
docker compose build
docker compose up -d

make dev
make server
pip install -r dev_requirements.txt
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,5 @@ ENV/
env.bak/
venv.bak/
.mise.toml

**devcontainer-lock.json**
14 changes: 7 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ default_language_version:
python: python3.10
repos:
- repo: 'https://github.com/pre-commit/pre-commit-hooks'
rev: v4.4.0
rev: v4.6.0
hooks:
- id: check-yaml
args:
Expand All @@ -21,7 +21,7 @@ repos:
- id: mixed-line-ending
- id: check-docstring-first
- repo: 'https://github.com/adrienverge/yamllint'
rev: v1.32.0
rev: v1.35.1
hooks:
- id: yamllint
args:
Expand All @@ -32,13 +32,13 @@ repos:
hooks:
- id: absolufy-imports
- repo: 'https://github.com/hadialqattan/pycln'
rev: v2.1.3
rev: v2.4.0
hooks:
- id: pycln
args:
- '--all'
- repo: 'https://github.com/pycqa/isort'
rev: 5.12.0
rev: 5.13.2
hooks:
- id: isort
args:
Expand All @@ -50,7 +50,7 @@ repos:
- '--python-version'
- '39'
- repo: 'https://github.com/psf/black'
rev: 23.3.0
rev: 24.8.0
hooks:
- id: black
args:
Expand All @@ -66,7 +66,7 @@ repos:
- '--check'
- '--diff'
- repo: 'https://github.com/pycqa/flake8'
rev: 6.0.0
rev: 7.1.1
hooks:
- id: flake8
args:
Expand All @@ -78,7 +78,7 @@ repos:
stages:
- manual
- repo: 'https://github.com/pre-commit/mirrors-mypy'
rev: v1.3.0
rev: v1.11.1
hooks:
- id: mypy
args:
Expand Down
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
# Changelog

### v1.8.0

Updates dbt-sqlserver to support dbt 1.8.

Notable changes

- Adopts `dbt-common` and `dbt-adapters` as the upstream, in line with dbt projects.
- Implements the majority of the tests from the `dbt-test-adapters` project to provide better coverage.
- Implements better testing for `dbt-sqlserver` specific functions, including indexes.
- Realigns to closer to the global project, overriding some fabric specific implementations

Update also fixes a number of regressions related to the fabric adapter. These include

- Proper ALTER syntax for column changes (in both )
- https://github.com/dbt-msft/dbt-sqlserver/pull/504/files
- Restoring cluster columntables post create on `tables`
- https://github.com/dbt-msft/dbt-sqlserver/issues/473
- Adds proper constraints to tables and columns
- https://github.com/dbt-msft/dbt-sqlserver/pull/500


### v1.7.2

Huge thanks to GitHub users **@cody-scott** and **@prescode** for help with this long-awaited update to enable `dbt-core` 1.7.2 compatibility!
Expand Down
10 changes: 5 additions & 5 deletions dbt/adapters/sqlserver/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from dbt.adapters.base import AdapterPlugin

from dbt.adapters.sqlserver.sql_server_adapter import SQLServerAdapter
from dbt.adapters.sqlserver.sql_server_column import SQLServerColumn
from dbt.adapters.sqlserver.sql_server_configs import SQLServerConfigs
from dbt.adapters.sqlserver.sql_server_connection_manager import SQLServerConnectionManager
from dbt.adapters.sqlserver.sql_server_credentials import SQLServerCredentials
from dbt.adapters.sqlserver.sqlserver_adapter import SQLServerAdapter
from dbt.adapters.sqlserver.sqlserver_column import SQLServerColumn
from dbt.adapters.sqlserver.sqlserver_configs import SQLServerConfigs
from dbt.adapters.sqlserver.sqlserver_connections import SQLServerConnectionManager # noqa
from dbt.adapters.sqlserver.sqlserver_credentials import SQLServerCredentials
from dbt.include import sqlserver

Plugin = AdapterPlugin(
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.7.4"
version = "1.8.0"
13 changes: 13 additions & 0 deletions dbt/adapters/sqlserver/relation_configs/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from dbt.adapters.sqlserver.relation_configs.policies import (
MAX_CHARACTERS_IN_IDENTIFIER,
SQLServerIncludePolicy,
SQLServerQuotePolicy,
SQLServerRelationType,
)

__all__ = [
"MAX_CHARACTERS_IN_IDENTIFIER",
"SQLServerIncludePolicy",
"SQLServerQuotePolicy",
"SQLServerRelationType",
]
25 changes: 25 additions & 0 deletions dbt/adapters/sqlserver/relation_configs/policies.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from dataclasses import dataclass

from dbt.adapters.contracts.relation import Policy
from dbt_common.dataclass_schema import StrEnum

MAX_CHARACTERS_IN_IDENTIFIER = 127


class SQLServerRelationType(StrEnum):
Table = "table"
View = "view"
CTE = "cte"


class SQLServerIncludePolicy(Policy):
database: bool = True
schema: bool = True
identifier: bool = True


@dataclass
class SQLServerQuotePolicy(Policy):
database: bool = True
schema: bool = True
identifier: bool = True
86 changes: 0 additions & 86 deletions dbt/adapters/sqlserver/sql_server_adapter.py

This file was deleted.

5 changes: 0 additions & 5 deletions dbt/adapters/sqlserver/sql_server_column.py

This file was deleted.

61 changes: 61 additions & 0 deletions dbt/adapters/sqlserver/sqlserver_adapter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
from typing import Optional

import dbt.exceptions
from dbt.adapters.base.impl import ConstraintSupport
from dbt.adapters.fabric import FabricAdapter
from dbt.contracts.graph.nodes import ConstraintType

from dbt.adapters.sqlserver.sqlserver_column import SQLServerColumn
from dbt.adapters.sqlserver.sqlserver_connections import SQLServerConnectionManager
from dbt.adapters.sqlserver.sqlserver_relation import SQLServerRelation


class SQLServerAdapter(FabricAdapter):
"""
Controls actual implmentation of adapter, and ability to override certain methods.
"""

ConnectionManager = SQLServerConnectionManager
Column = SQLServerColumn
Relation = SQLServerRelation

CONSTRAINT_SUPPORT = {
ConstraintType.check: ConstraintSupport.ENFORCED,
ConstraintType.not_null: ConstraintSupport.ENFORCED,
ConstraintType.unique: ConstraintSupport.ENFORCED,
ConstraintType.primary_key: ConstraintSupport.ENFORCED,
ConstraintType.foreign_key: ConstraintSupport.ENFORCED,
}

@classmethod
def render_model_constraint(cls, constraint) -> Optional[str]:
constraint_prefix = "add constraint "
column_list = ", ".join(constraint.columns)

if constraint.name is None:
raise dbt.exceptions.DbtDatabaseError(
"Constraint name cannot be empty. Provide constraint name - column "
+ column_list
+ " and run the project again."
)

if constraint.type == ConstraintType.unique:
return constraint_prefix + f"{constraint.name} unique nonclustered({column_list})"
elif constraint.type == ConstraintType.primary_key:
return constraint_prefix + f"{constraint.name} primary key nonclustered({column_list})"
elif constraint.type == ConstraintType.foreign_key and constraint.expression:
return (
constraint_prefix
+ f"{constraint.name} foreign key({column_list}) references "
+ constraint.expression
)
elif constraint.type == ConstraintType.check and constraint.expression:
return f"{constraint_prefix} {constraint.name} check ({constraint.expression})"
elif constraint.type == ConstraintType.custom and constraint.expression:
return f"{constraint_prefix} {constraint.name} {constraint.expression}"
else:
return None

@classmethod
def date_function(cls):
return "getdate()"
22 changes: 22 additions & 0 deletions dbt/adapters/sqlserver/sqlserver_column.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from dbt.adapters.fabric import FabricColumn


class SQLServerColumn(FabricColumn):
def is_integer(self) -> bool:
return self.dtype.lower() in [
# real types
"smallint",
"integer",
"bigint",
"smallserial",
"serial",
"bigserial",
# aliases
"int2",
"int4",
"int8",
"serial2",
"serial4",
"serial8",
"int",
]
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

@dataclass
class SQLServerConfigs(FabricConfigs):
...
pass
Loading
Loading