|
5 | 5 | - can be (re)used across dbt projects running on Azure databases |
6 | 6 | - 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. |
7 | 7 |
|
| 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 | + |
8 | 21 | ## Installation Instructions |
9 | 22 |
|
10 | 23 | 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` |
12 | 25 | ```yaml |
13 | 26 | 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} |
16 | 30 | - package: dbt-msft/tsql_utils |
17 | | - version: 0.6.4.1 |
| 31 | + version: {SEE DBT HUB FOR NEWEST VERSION} |
18 | 32 | ``` |
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` |
20 | 34 | ```yaml |
21 | 35 | vars: |
22 | 36 | dbt_utils_dispatch_list: ['tsql_utils'] |
| 37 | + dbt_date_dispatch_list: ['tsql_utils'] |
| 38 | + dbt_expectations_dispatch_list: ['tsql_utils'] |
23 | 39 | ``` |
24 | 40 | Check [dbt Hub](https://hub.getdbt.com) for the latest installation |
25 | 41 | 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. |
0 commit comments