Feature overview

The SELECT dbt integration allows you better understand and optimize Snowflake spend attributed to dbt.

  • Dissect your dbt spend across a variety of different dimensions such as project, target, materialization and resource type.
  • Identify expensive models and tests, and understand how their cost and performance varies over time.
  • Drill into the execution history of any dbt resource and view query profile diagnostics for each run.
  • Receive tailored optimization recommendations to improve model cost and performance

SELECT uses query tags and comment metadata to power this integration. To enable this integration, follow the configuration steps below.


Step 1: Update packages.yml

Add the following entry to your dbt project's packages.yml file in the root of the dbt project, creating the file if it doesn't exist:

- package: get-select/dbt_snowflake_query_tags
version: [">=2.0.0", "<3.0.0"]

Step 2: Adding the query tags

Option 1: If running dbt >= 1.2, simply configure the dispatch search order in dbt_project.yml.

- macro_namespace: dbt
- dbt_snowflake_query_tags
- dbt

Option 2: If running dbt < 1.2, create a folder named macros in your dbt project's top level directory (if it doesn't exist). Inside, make a new file called query_tags.sql with the following content:

{% macro set_query_tag() -%}
{% do return(dbt_snowflake_query_tags.set_query_tag()) %}
{% endmacro %}
{% macro unset_query_tag(original_query_tag) -%}
{% do return(dbt_snowflake_query_tags.unset_query_tag(original_query_tag)) %}
{% endmacro %}

Step 3: Configure the query comments

Add the following config to dbt_project.yml.

comment: '{{ dbt_snowflake_query_tags.get_query_comment(node) }}'
append: true # Snowflake removes prefixed comments.

That's it! All dbt-issued queries will now be tagged.

Example dbt query metadata

This configuration adds metadata describing each dbt-issued query to a tag on the query. Once enabled, SELECT will begin to provide insights, analytics and recommendations on your dbt project. An example of the metadata added to each query is shown below:

"dbt_snowflake_query_tags_version": "2.0.0",
"app": "dbt",
"dbt_version": "1.4.0",
"project_name": "my_project",
"target_name": "dev",
"target_database": "dev",
"target_schema": "larry_goldings",
"invocation_id": "c784c7d0-5c3f-4765-805c-0a377fefcaa0",
"node_name": "orders",
"node_alias": "orders",
"node_package_name": "my_project",
"node_original_file_path": "models/staging/orders.sql",
"node_database": "dev",
"node_schema": "mart",
"node_id": "model.my_project.orders",
"node_resource_type": "model",
"materialized": "incremental",
"is_incremental": true

Step 4: All done!

That's all that's required for setup. The next time your dbt project runs, the generated queries will automatically be tagged with this metadata. SELECT will then process this query metadata and present it back to you in the web application.

Leveraging dbt meta & tags

Considering the example dbt_project.yml below, which implements a combination of dbt meta fields and tags.

# dbt_project.yml
name: 'select_dbt'
version: '1.0.0'
config-version: 2
team: 'data' # all models get tagged with team = 'data' by default
team: 'engineering'
team: 'marketing'
team: 'finance'
- "sensitive"
- "critical"

The file structure for this dbt project would look something like what is shown below. All resources under the engineering directory would be get a team meta field added with the value engineering. Similarly, the one model in the forecasts directory would get a team field of finance added. It would also have following tags: ["sensitive", "critical"].

├── dbt_project.yml
├── packages.yml
└── models/
├── engineering/
| ├── syncs.sql
| └── ai.sql
├── marketing/
| ├── attribition.sql
| └── page_clicks.sql
└── forecasts/
└── forecast.sql

To expose dbt meta fields in SELECT, you can go into the settings and specify which fields you want enabled. No such specification is required for dbt tags.

SELECT dbt meta keys settings

Once added, you can filter and slice by this metadata throught the UI!

Leverage dbt metadata in your Usage Groups

Looking to do cost chargebacks or showbacks using dbt metadata? You can now flexibly allocate costs using dbt meta fields and tags you've specified using SELECT's Usage Groups feature!