Skip to content

Commit d1c741e

Browse files
authored
Add dbt date shims (pt 2) (#40)
* needed for dbt_expectations_integration_tests.data_test * enable testing for dbt_expectations * typos * dbt_expectations_integration_test.timeseries_data * ln not supported in TSQL * dbt-utils via dbt-date * add CI * group by explicit column name * TEMP point to fork * test for dbt-expectations * typo * always spin down after * testing * actual logs * repo name not cloned * top-level * per calogica/dbt-expectations#53 * specify outputs * redundant * re-enable * TEMP: disable tests * typo * add dbt-date as submodule * typo * correct directory * for integration tests * dbt-date integration test project * mimic dbt-date ordering * synapse can't handle dateadd hour w/ date type * update upstream * trim ws * only synapse is incompatible * faster CI * unneeded * add deps and required macros * auto-testing * dispatch to synapse * also test synapse * Update .gitmodules * break out into standalone file * new changes * redundant * final two tests * generalize & refresh docs * both packages
1 parent 9d23be3 commit d1c741e

File tree

19 files changed

+246
-62
lines changed

19 files changed

+246
-62
lines changed

.circleci/config.yml

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,28 @@ jobs:
7070
- store_artifacts:
7171
path: /root/project/integration_tests/dbt_expectations/target
7272

73+
integration-dbt-date-azuresql:
74+
docker:
75+
- image: dbtmsft/msodbc_py:0.5
76+
steps:
77+
- checkout
78+
- azure-cli/install
79+
- azure-cli/login-with-service-principal: *azure-creds
80+
- run: *pull-submodules
81+
- run: *setup-dbt
82+
- run:
83+
name: "Run Tests - dbt-date"
84+
command: |
85+
. venv/bin/activate
86+
cd integration_tests/dbt_date
87+
dbt deps --target azuresql
88+
dbt run --target azuresql --full-refresh
89+
dbt test --target azuresql
90+
- store_artifacts:
91+
path: /root/project/integration_tests/dbt_date/logs/dbt.log
92+
- store_artifacts:
93+
path: /root/project/integration_tests/dbt_date/target
94+
7395
integration-dbt-utils-synapse:
7496
docker:
7597
- image: dbtmsft/msodbc_py:0.5
@@ -123,13 +145,37 @@ jobs:
123145
- store_artifacts:
124146
path: ./logs
125147

148+
integration-dbt-date-synapse:
149+
docker:
150+
- image: dbtmsft/msodbc_py:0.5
151+
steps:
152+
- checkout
153+
- run: *pull-submodules
154+
- azure-cli/install
155+
- azure-cli/login-with-service-principal: *azure-creds
156+
- run: *setup-dbt
157+
- run: *start-synapse
158+
- run:
159+
name: "Run Tests - dbt-date"
160+
command: |
161+
. venv/bin/activate
162+
cd integration_tests/dbt_date
163+
dbt deps --target synapse
164+
dbt run --target synapse --full-refresh
165+
dbt test --target synapse
166+
- run: *pause-synapse
167+
- store_artifacts:
168+
path: ./logs
169+
126170

127171
workflows:
128172
version: 2
129173
test-all:
130174
jobs:
131-
- integration-dbt-expectations-azuresql: &dbt-context
175+
- integration-dbt-utils-azuresql: &dbt-context
132176
context: DBT_SYNAPSE_PROFILE
133-
- integration-dbt-utils-azuresql: *dbt-context
134177
- integration-dbt-utils-synapse: *dbt-context
178+
- integration-dbt-expectations-azuresql: *dbt-context
135179
- integration-dbt-expectations-synapse: *dbt-context
180+
- integration-dbt-date-azuresql: *dbt-context
181+
- integration-dbt-date-synapse: *dbt-context

.gitmodules

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,7 @@
66
path = dbt-expectations
77
url = https://github.com/calogica/dbt-expectations
88
branch = main
9+
[submodule "dbt-date"]
10+
path = dbt-date
11+
url = https://github.com/calogica/dbt-date
12+
branch = main

CHANGELOG.md

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

3+
## `0.6.7`
4+
5+
## New features
6+
7+
- shim dbt-date, currently passing all tests! [#36](https://github.com/dbt-msft/tsql-utils/pull/36)
8+
- support for `dbt_utils.generate_series()` [#36](https://github.com/dbt-msft/tsql-utils/pull/36)
9+
- support on synapse for `dbt_utils.dateadd()` and `dbt_utils.datediff()` [#36](https://github.com/dbt-msft/tsql-utils/pull/36)
10+
11+
### Under the hood
12+
- add CI infrastucture for dbt-date and dbt-expectations [#35](https://github.com/dbt-msft/tsql-utils/pull/35) thanks to [@b-per](https://github.com/b-per) for all the heaving lifting with [calogica/dbt-expectations #29](https://github.com/calogica/dbt-expectations/pull/29), [calogica/dbt-date #14](https://github.com/calogica/dbt-date/pull/14), and [calogica/dbt-date #15](https://github.com/calogica/dbt-date/pull/15)
13+
- docs refresh
314

415
## `0.6.6`
516

CONTRIBUTING.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
## Contributions
2+
3+
### Help out!
4+
5+
There are a number of macros that have yet to be implemented for T-SQL. Check out
6+
- the issues page, or
7+
- [this file](integration_tests/dbt_utils/dbt_project.yml) for an idea of which macros are not currently supported.
8+
9+
### Dev environment set-up
10+
11+
0. clone this repo
12+
1. open terminal in top-level dir of project
13+
2. run the following to install dbt-utils as a submodule
14+
`git clone --recursive https://github.com/fishtown-analytics/dbt-utils`
15+
3. open terminal in `integration_tests/dbt_utils`
16+
4. configure your `~/.dbt/profiles.yml` to have an `integration_tests` section with a `sqlserver` target set as the default like `integrations_tests/ci/sample.profiles.yml` does
17+
5. run all the commands listed in the "Run Tests - dbt-utils" step of `.circleci/config.yml` namely:
18+
```bash
19+
dbt deps --target sqlserver
20+
dbt seed --target sqlserver --full-refresh
21+
dbt run --target sqlserver --full-refresh
22+
dbt test --target sqlserver
23+
```
24+
25+
### Multi-Adapter Support
26+
27+
t-sql-utils applies for 2 adapters, sqlserver and synapse.
28+
29+
Therefore, for the time being, a macro should be implemented twice, once for the functionality and once as a reference for the second adapter.
30+
31+
Imagine an adapter plugin, dbt-synapse, that inherits from dbt-sqlserver.
32+
For the time being, we need to explicitly reimplement sqlserver__ macros as synapse__ macros. This looks like:
33+
34+
```
35+
{% macro synapse__get_tables_by_pattern_sql(field) %}
36+
{% do return( tsql_utils.sqlserver__get_tables_by_pattern_sql(schema_pattern, table_pattern, exclude='', database=target.database)) %}
37+
{% endmacro %}
38+
```
39+
40+
TODO: We can make a small change to dbt-core (https://github.com/fishtown-analytics/dbt/issues/2923) that will make the inheritance of dispatched macros work just like the inheritance of other adapter objects, and render the following code redundant.

README.md

Lines changed: 22 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -5,74 +5,38 @@ that:
55
- can be (re)used across dbt projects running on Azure databases
66
- define implementations of [dispatched macros](https://docs.getdbt.com/reference/dbt-jinja-functions/adapter/#dispatch) from other packages that can be used on a database that speaks T-SQL: SQL Server, Azure SQL, Azure Synapse, etc.
77

8+
## Compatibility
9+
10+
This package provides "shims" for:
11+
- [dbt-utils](https://github.com/fishtown-analytics/dbt-utils) (partial)
12+
- [dbt-date](https://github.com/calogica/dbt-date) (partial)
13+
- (coming soon!) [dbt-expectations](https://github.com/calogica/dbt-expectations) (coming soon!)
14+
15+
16+
## Usage
17+
18+
Wherever a custom tsql macro exists, dbt_utils adapter dispatch will pass to tsq_utils. This means you can just do `{{dbt_utils.hash('mycolumnname')}}` just like your friends with Snowflake.
19+
20+
821
## Installation Instructions
922

1023
To make use of these TSQL adaptations in your dbt project, you must do two things:
11-
1. Install both `dbt-utils` and `tsql-utils` by adding the following to your `packages.yml`
24+
1. Install both and `tsql-utils` and any of the compatible packages listed above by them to your `packages.yml`
1225
```yaml
1326
packages:
14-
- package: fishtown-analytics/dbt_utils
15-
version: 0.6.4.1
27+
# and/or calogica/dbt-date; calogica/dbt-expectations
28+
- package: fishtown-analytics/dbt_utils
29+
version: {SEE DBT HUB FOR NEWEST VERSION}
1630
- package: dbt-msft/tsql_utils
17-
version: 0.6.4.1
31+
version: {SEE DBT HUB FOR NEWEST VERSION}
1832
```
19-
2. Tell `dbt-utils` to also look for the `tsql-utils` macros by adding this section to your `dbt_project.yml`
33+
2. Tell the supported package to also look for the `tsql-utils` macros by adding the relevant variables to your `dbt_project.yml`
2034
```yaml
2135
vars:
2236
dbt_utils_dispatch_list: ['tsql_utils']
37+
dbt_date_dispatch_list: ['tsql_utils']
38+
dbt_expectations_dispatch_list: ['tsql_utils']
2339
```
2440
Check [dbt Hub](https://hub.getdbt.com) for the latest installation
2541
instructions, or [read the docs](https://docs.getdbt.com/docs/package-management)
26-
for more information on installing packages.
27-
28-
----
29-
30-
## Usage
31-
32-
Wherever a custom tsql macro exists, dbt_utils adapter dispatch will pass to tsq_utils. This means you can just do `{{dbt_utils.hash('mycolumnname')}}` just like your friends with Snowflake.
33-
34-
## Compatibility
35-
36-
This package provides "shims" for:
37-
- [dbt_utils](https://github.com/fishtown-analytics/dbt-utils) (partial)
38-
39-
## Contributions
40-
41-
### Help out!
42-
43-
There are a number of macros that have yet to be implemented for T-SQL. Check out
44-
- the issues page, or
45-
- [this file](integration_tests/dbt_utils/dbt_project.yml) for an idea of which macros are not currently supported.
46-
47-
### Dev environment set-up
48-
49-
0. clone this repo
50-
1. open terminal in top-level dir of project
51-
2. run the following to install dbt-utils as a submodule
52-
`git clone --recursive https://github.com/fishtown-analytics/dbt-utils`
53-
3. open terminal in `integration_tests/dbt_utils`
54-
4. configure your `~/.dbt/profiles.yml` to have an `integration_tests` section with a `sqlserver` target set as the default like `integrations_tests/ci/sample.profiles.yml` does
55-
5. run all the commands listed in the "Run Tests - dbt-utils" step of `.circleci/config.yml` namely:
56-
```bash
57-
dbt deps --target sqlserver
58-
dbt seed --target sqlserver --full-refresh
59-
dbt run --target sqlserver --full-refresh
60-
dbt test --target sqlserver
61-
```
62-
63-
### Multi-Adapter Support
64-
65-
t-sql-utils applies for 2 adapters, sqlserver and synapse.
66-
67-
Therefore, for the time being, a macro should be implemented twice, once for the functionality and once as a reference for the second adapter.
68-
69-
Imagine an adapter plugin, dbt-synapse, that inherits from dbt-sqlserver.
70-
For the time being, we need to explicitly reimplement sqlserver__ macros as synapse__ macros. This looks like:
71-
72-
```
73-
{% macro synapse__get_tables_by_pattern_sql(field) %}
74-
{% do return( tsql_utils.sqlserver__get_tables_by_pattern_sql(schema_pattern, table_pattern, exclude='', database=target.database)) %}
75-
{% endmacro %}
76-
```
77-
78-
TODO: We can make a small change to dbt-core (https://github.com/fishtown-analytics/dbt/issues/2923) that will make the inheritance of dispatched macros work just like the inheritance of other adapter objects, and render the following code redundant.
42+
for more information on installing packages.

dbt-date

Submodule dbt-date added at e58387d
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: 'tsql_utils_dbt_date_integration_tests'
2+
version: '1.0'
3+
config-version: 2
4+
5+
profile: 'integration_tests'
6+
7+
source-paths: ["models"]
8+
analysis-paths: ["analysis"]
9+
test-paths: ["tests"]
10+
data-paths: ["data"]
11+
macro-paths: ["macros"]
12+
13+
target-path: "target"
14+
clean-targets:
15+
- "target"
16+
- "dbt_modules"
17+
18+
require-dbt-version: ">=0.18.1"
19+
20+
vars:
21+
'dbt_date:time_zone': 'Pacific Standard Time'
22+
dbt_utils_dispatch_list: ['tsql_utils']
23+
dbt_date_dispatch_list: ['tsql_utils']
24+
25+
quoting:
26+
database: true
27+
identifier: true
28+
schema: true
29+
30+
models:
31+
dbt_date_integration_tests:
32+
+schema: dbt_date_integration_tests
33+
+materialized: table
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
packages:
3+
- local: ../../ # tsql_utils main macros
4+
- local: ../../dbt-date # actual dbt-expectations package as submodule
5+
- local: ../../dbt-date/integration_tests # nothing here for now

integration_tests/dbt_expectations/dbt_project.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ clean-targets: # directories to be removed by `dbt clean`
1717
- "dbt_modules"
1818

1919
vars:
20+
'dbt_date:time_zone': 'Pacific Standard Time'
2021
dbt_utils_dispatch_list: ['tsql_utils']
21-
dbt_expectations_dispatch_list: ['tsql_utils']
2222
dbt_date_dispatch_list: ['tsql_utils']
23-
'dbt_date:time_zone': 'Pacific Standard Time'
23+
dbt_expectations_dispatch_list: ['tsql_utils']
2424

2525
models:
2626
dbt_expectations_integration_tests:

0 commit comments

Comments
 (0)