Skip to content

Commit 09b577b

Browse files
authored
Merge pull request #513 from cody-scott/1.8-and-tests
DBT 1.8 and test coverage updates
2 parents f789ab0 + e7d908b commit 09b577b

File tree

94 files changed

+3728
-2091
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+3728
-2091
lines changed

.devcontainer/devcontainer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"features": {
55
"ghcr.io/devcontainers/features/docker-in-docker:2": {}
66
},
7-
"postStartCommand": "sudo bash .devcontainer/setup_odbc.sh && bash .devcontainer/install_pyenv.sh && bash .devcontainer/setup_env.sh",
7+
"forwardPorts": [1433],
8+
"postStartCommand": "/bin/bash ./.devcontainer/setup_odbc.sh & /bin/bash ./.devcontainer/setup_env.sh",
89
"containerEnv": {
910
"SQLSERVER_TEST_DRIVER": "ODBC Driver 18 for SQL Server",
1011
"SQLSERVER_TEST_HOST": "127.0.0.1",

.devcontainer/setup_env.sh

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
cp test.env.sample test.env
22

3-
pyenv install 3.10.7
4-
pyenv virtualenv 3.10.7 dbt-sqlserver
5-
pyenv activate dbt-sqlserver
3+
docker compose build
4+
docker compose up -d
65

7-
make dev
8-
make server
6+
pip install -r dev_requirements.txt

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,5 @@ ENV/
9696
env.bak/
9797
venv.bak/
9898
.mise.toml
99+
100+
**devcontainer-lock.json**

.pre-commit-config.yaml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ default_language_version:
22
python: python3.10
33
repos:
44
- repo: 'https://github.com/pre-commit/pre-commit-hooks'
5-
rev: v4.4.0
5+
rev: v4.6.0
66
hooks:
77
- id: check-yaml
88
args:
@@ -21,7 +21,7 @@ repos:
2121
- id: mixed-line-ending
2222
- id: check-docstring-first
2323
- repo: 'https://github.com/adrienverge/yamllint'
24-
rev: v1.32.0
24+
rev: v1.35.1
2525
hooks:
2626
- id: yamllint
2727
args:
@@ -32,13 +32,13 @@ repos:
3232
hooks:
3333
- id: absolufy-imports
3434
- repo: 'https://github.com/hadialqattan/pycln'
35-
rev: v2.1.3
35+
rev: v2.4.0
3636
hooks:
3737
- id: pycln
3838
args:
3939
- '--all'
4040
- repo: 'https://github.com/pycqa/isort'
41-
rev: 5.12.0
41+
rev: 5.13.2
4242
hooks:
4343
- id: isort
4444
args:
@@ -50,7 +50,7 @@ repos:
5050
- '--python-version'
5151
- '39'
5252
- repo: 'https://github.com/psf/black'
53-
rev: 23.3.0
53+
rev: 24.8.0
5454
hooks:
5555
- id: black
5656
args:
@@ -66,7 +66,7 @@ repos:
6666
- '--check'
6767
- '--diff'
6868
- repo: 'https://github.com/pycqa/flake8'
69-
rev: 6.0.0
69+
rev: 7.1.1
7070
hooks:
7171
- id: flake8
7272
args:
@@ -78,7 +78,7 @@ repos:
7878
stages:
7979
- manual
8080
- repo: 'https://github.com/pre-commit/mirrors-mypy'
81-
rev: v1.3.0
81+
rev: v1.11.1
8282
hooks:
8383
- id: mypy
8484
args:

CHANGELOG.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,26 @@
11
# Changelog
22

3+
### v1.8.0
4+
5+
Updates dbt-sqlserver to support dbt 1.8.
6+
7+
Notable changes
8+
9+
- Adopts `dbt-common` and `dbt-adapters` as the upstream, in line with dbt projects.
10+
- Implements the majority of the tests from the `dbt-test-adapters` project to provide better coverage.
11+
- Implements better testing for `dbt-sqlserver` specific functions, including indexes.
12+
- Realigns to closer to the global project, overriding some fabric specific implementations
13+
14+
Update also fixes a number of regressions related to the fabric adapter. These include
15+
16+
- Proper ALTER syntax for column changes (in both )
17+
- https://github.com/dbt-msft/dbt-sqlserver/pull/504/files
18+
- Restoring cluster columntables post create on `tables`
19+
- https://github.com/dbt-msft/dbt-sqlserver/issues/473
20+
- Adds proper constraints to tables and columns
21+
- https://github.com/dbt-msft/dbt-sqlserver/pull/500
22+
23+
324
### v1.7.2
425

526
Huge thanks to GitHub users **@cody-scott** and **@prescode** for help with this long-awaited update to enable `dbt-core` 1.7.2 compatibility!

dbt/adapters/sqlserver/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
from dbt.adapters.base import AdapterPlugin
22

3-
from dbt.adapters.sqlserver.sql_server_adapter import SQLServerAdapter
4-
from dbt.adapters.sqlserver.sql_server_column import SQLServerColumn
5-
from dbt.adapters.sqlserver.sql_server_configs import SQLServerConfigs
6-
from dbt.adapters.sqlserver.sql_server_connection_manager import SQLServerConnectionManager
7-
from dbt.adapters.sqlserver.sql_server_credentials import SQLServerCredentials
3+
from dbt.adapters.sqlserver.sqlserver_adapter import SQLServerAdapter
4+
from dbt.adapters.sqlserver.sqlserver_column import SQLServerColumn
5+
from dbt.adapters.sqlserver.sqlserver_configs import SQLServerConfigs
6+
from dbt.adapters.sqlserver.sqlserver_connections import SQLServerConnectionManager # noqa
7+
from dbt.adapters.sqlserver.sqlserver_credentials import SQLServerCredentials
88
from dbt.include import sqlserver
99

1010
Plugin = AdapterPlugin(

dbt/adapters/sqlserver/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version = "1.7.4"
1+
version = "1.8.0"
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from dbt.adapters.sqlserver.relation_configs.policies import (
2+
MAX_CHARACTERS_IN_IDENTIFIER,
3+
SQLServerIncludePolicy,
4+
SQLServerQuotePolicy,
5+
SQLServerRelationType,
6+
)
7+
8+
__all__ = [
9+
"MAX_CHARACTERS_IN_IDENTIFIER",
10+
"SQLServerIncludePolicy",
11+
"SQLServerQuotePolicy",
12+
"SQLServerRelationType",
13+
]
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from dataclasses import dataclass
2+
3+
from dbt.adapters.contracts.relation import Policy
4+
from dbt_common.dataclass_schema import StrEnum
5+
6+
MAX_CHARACTERS_IN_IDENTIFIER = 127
7+
8+
9+
class SQLServerRelationType(StrEnum):
10+
Table = "table"
11+
View = "view"
12+
CTE = "cte"
13+
14+
15+
class SQLServerIncludePolicy(Policy):
16+
database: bool = True
17+
schema: bool = True
18+
identifier: bool = True
19+
20+
21+
@dataclass
22+
class SQLServerQuotePolicy(Policy):
23+
database: bool = True
24+
schema: bool = True
25+
identifier: bool = True

dbt/adapters/sqlserver/sql_server_adapter.py

Lines changed: 0 additions & 86 deletions
This file was deleted.

dbt/adapters/sqlserver/sql_server_column.py

Lines changed: 0 additions & 5 deletions
This file was deleted.
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
from typing import Optional
2+
3+
import dbt.exceptions
4+
from dbt.adapters.base.impl import ConstraintSupport
5+
from dbt.adapters.fabric import FabricAdapter
6+
from dbt.contracts.graph.nodes import ConstraintType
7+
8+
from dbt.adapters.sqlserver.sqlserver_column import SQLServerColumn
9+
from dbt.adapters.sqlserver.sqlserver_connections import SQLServerConnectionManager
10+
from dbt.adapters.sqlserver.sqlserver_relation import SQLServerRelation
11+
12+
13+
class SQLServerAdapter(FabricAdapter):
14+
"""
15+
Controls actual implmentation of adapter, and ability to override certain methods.
16+
"""
17+
18+
ConnectionManager = SQLServerConnectionManager
19+
Column = SQLServerColumn
20+
Relation = SQLServerRelation
21+
22+
CONSTRAINT_SUPPORT = {
23+
ConstraintType.check: ConstraintSupport.ENFORCED,
24+
ConstraintType.not_null: ConstraintSupport.ENFORCED,
25+
ConstraintType.unique: ConstraintSupport.ENFORCED,
26+
ConstraintType.primary_key: ConstraintSupport.ENFORCED,
27+
ConstraintType.foreign_key: ConstraintSupport.ENFORCED,
28+
}
29+
30+
@classmethod
31+
def render_model_constraint(cls, constraint) -> Optional[str]:
32+
constraint_prefix = "add constraint "
33+
column_list = ", ".join(constraint.columns)
34+
35+
if constraint.name is None:
36+
raise dbt.exceptions.DbtDatabaseError(
37+
"Constraint name cannot be empty. Provide constraint name - column "
38+
+ column_list
39+
+ " and run the project again."
40+
)
41+
42+
if constraint.type == ConstraintType.unique:
43+
return constraint_prefix + f"{constraint.name} unique nonclustered({column_list})"
44+
elif constraint.type == ConstraintType.primary_key:
45+
return constraint_prefix + f"{constraint.name} primary key nonclustered({column_list})"
46+
elif constraint.type == ConstraintType.foreign_key and constraint.expression:
47+
return (
48+
constraint_prefix
49+
+ f"{constraint.name} foreign key({column_list}) references "
50+
+ constraint.expression
51+
)
52+
elif constraint.type == ConstraintType.check and constraint.expression:
53+
return f"{constraint_prefix} {constraint.name} check ({constraint.expression})"
54+
elif constraint.type == ConstraintType.custom and constraint.expression:
55+
return f"{constraint_prefix} {constraint.name} {constraint.expression}"
56+
else:
57+
return None
58+
59+
@classmethod
60+
def date_function(cls):
61+
return "getdate()"
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from dbt.adapters.fabric import FabricColumn
2+
3+
4+
class SQLServerColumn(FabricColumn):
5+
def is_integer(self) -> bool:
6+
return self.dtype.lower() in [
7+
# real types
8+
"smallint",
9+
"integer",
10+
"bigint",
11+
"smallserial",
12+
"serial",
13+
"bigserial",
14+
# aliases
15+
"int2",
16+
"int4",
17+
"int8",
18+
"serial2",
19+
"serial4",
20+
"serial8",
21+
"int",
22+
]

dbt/adapters/sqlserver/sql_server_configs.py renamed to dbt/adapters/sqlserver/sqlserver_configs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55

66
@dataclass
77
class SQLServerConfigs(FabricConfigs):
8-
...
8+
pass

0 commit comments

Comments
 (0)