0
0
dbtdata~5 mins

Tags and selectors for partial runs in dbt

Choose your learning style9 modes available
Introduction

Tags and selectors help you run only parts of your dbt project. This saves time and focuses on what you need.

You want to test just one feature or model without running everything.
You fixed a bug in a few models and want to rebuild only those.
You want to run models related to a specific business area.
You want to speed up development by running a small subset.
You want to run models tagged as 'nightly' only during off-hours.
Syntax
dbt
dbt run --select tag:<tag_name>
dbt run --select <selector_name>

Use --select tag:<tag_name> to run models with a specific tag.

Selectors are reusable groups of models defined in selectors.yml.

Examples
This runs only models tagged with finance.
dbt
dbt run --select tag:finance
This runs models grouped under the selector named my_selector.
dbt
dbt run --select my_selector
This runs models tagged marketing and all their dependencies.
dbt
dbt run --select tag:marketing+
Sample Program

This example shows how to tag models and define a selector. Running dbt run --select finance_models runs only models tagged with finance.

dbt
version: 2

models:
  - name: sales
    tags: ['finance', 'daily']
  - name: customers
    tags: ['marketing']

# selectors.yml
selectors:
  - name: finance_models
    definition:
      method: tag
      value: finance

# Command to run:
dbt run --select finance_models
OutputSuccess
Important Notes

You can combine tags and selectors for flexible runs.

Use + after a tag to include dependencies.

Selectors are defined in selectors.yml in your dbt project.

Summary

Tags mark models for easy grouping.

Selectors let you run groups of models by name.

Use tags and selectors to run only what you need, saving time.