This dbt package contains macros that:
- can be (re)used across dbt projects running on Azure databases
- define implementations of dispatched macros from other packages that can be used on a database that speaks T-SQL: SQL Server, Azure SQL, Azure Synapse, etc.
To make use of these TSQL adaptations in your dbt project, you must do two things:
- Install both
dbt-utils
andtsql-utils
by adding the following to yourpackages.yml
packages: - package: fishtown-analytics/dbt_utils version: 0.6.4.1 - package: dbt-msft/tsql_utils version: 0.6.4.1
- Tell
dbt-utils
to also look for thetsql-utils
macros by adding this section to yourdbt_project.yml
vars: dbt_utils_dispatch_list: ['tsql_utils']
Check dbt Hub for the latest installation instructions, or read the docs for more information on installing packages.
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.
This package provides "shims" for:
- dbt_utils (partial)
There are a number of macros that have yet to be implemented for T-SQL. Check out
- the issues page, or
- this file for an idea of which macros are not currently supported.
- clone this repo
- open terminal in top-level dir of project
- run the following to install dbt-utils as a submodule
git clone --recursive https://github.com/fishtown-analytics/dbt-utils
- open terminal in
integration_tests/dbt_utils
- configure your
~/.dbt/profiles.yml
to have anintegration_tests
section with asqlserver
target set as the default likeintegrations_tests/ci/sample.profiles.yml
does - run all the commands listed in the "Run Tests - dbt-utils" step of
.circleci/config.yml
namely:dbt deps --target sqlserver dbt seed --target sqlserver --full-refresh dbt run --target sqlserver --full-refresh dbt test --target sqlserver
t-sql-utils applies for 2 adapters, sqlserver and synapse.
Therefore, for the time being, a macro should be implemented twice, once for the functionality and once as a reference for the second adapter.
Imagine an adapter plugin, dbt-synapse, that inherits from dbt-sqlserver. For the time being, we need to explicitly reimplement sqlserver__ macros as synapse__ macros. This looks like:
{% macro synapse__get_tables_by_pattern_sql(field) %}
{% do return( tsql_utils.sqlserver__get_tables_by_pattern_sql(schema_pattern, table_pattern, exclude='', database=target.database)) %}
{% endmacro %}
TODO: We can make a small change to dbt-core (dbt-labs/dbt-core#2923) that will make the inheritance of dispatched macros work just like the inheritance of other adapter objects, and render the following code redundant.