When developing new models using dbt (data base tool), I often find myself using the following run commands:
Run specific model
dbt run -–select model_alpha
Instead of running the whole dbt project, the above command allows you to runs (and thus test) only the model you have just created. In the above example, the model to be run in model_alpha
. To run more than one model, simply list their names in succession, e.g. dbt run -–select model_alpha model_beta
.
Run models downstream
dbt run –-select source:source_one.model_alpha+
This command runs all models that are directly and indirectly dependent on the source table model_alpha
, which makes part of source_one
. In your project’s schema.yml file, the source and model in the example would look like this:
- name: source_one
description: This is my first source
database: testingdb
schema: sandbox
tables:
- name: model_alpha
Run models upstream and downstream
dbt run -–select +model_apha+
As in the previous point, use the “+” sign as a prefix and/or suffix in order to run all models upstream and/or downstream from the model in question. The upstream models and downstream models are also referred to as a model’s ancestors and descendants, respectively.
Run specific models by tag
dbt run --select tag:user
The above command will run all models with the tag user
. Tags can be assigned on either a model’s configuration options or a model’s dbt_project.yml file. To run all those models associated with two tags, say the tags user
and test
, at the same time, then try dbt run –-select tag:user tag:test
.
For more on running specific models, refer to dbt’s documentation.