Only run a set of models?
Asked Answered
E

3

17

I started to migrate some of your transformations jobs to DBT. As you can see on the image bellow, there is usually 1 to 2 transformations before to have our final table (up to 5 transformations in some cases).

What I am trying to achieve is to do dbt run only for a set on linked model. For instance, sales_prediction and forecast. I am currently able to run either for everything with dbt run or just speficif model using dbt run --select model_name

enter image description here

Exhaust answered 29/6, 2022 at 9:45 Comment(1)
Docs are your friend: docs.getdbt.com/reference/node-selection/syntaxLyrist
J
21

Dbt allows syntax of

  • selecting a node and all nodes it requires (+ before the model name)
  • selecting a node and all nodes that depend on it (+ after the model name)
  • you can also do both (+model_name+)

In your case dbt run --select +forecast should do the trick

Also check the documentation of the + operator.

Jarrodjarrow answered 29/6, 2022 at 10:8 Comment(0)
G
16

In addition to the + operator, incase you just need to run multiple unrelated models by specifying their names, you can do so as such:

dbt run --select my_first_model my_second_model
Guardsman answered 15/3, 2023 at 14:4 Comment(2)
You need to add quotation marks: dbt run --select "my_first_model my_second_model"Leonardaleonardi
No AFAIK quotes are not necessary as they are two distinct unrelated modelsGuardsman
C
5

In order to run a model as well as its children (aka downstream dependencies), you'll have to specify the model name followed by + operator in the --select argument:

dbt run --select sales_prediction+

Likewise, to run a model and its parent (or upstream) dependencies, the + operator must be followed by the model name:

dbt run --select +sales_prediction

You can also run both the upstream and downstream dependencies

dbt run --select +sales_prediction+

You can even choose the level of depth a specific command will go. For example, the following command will run the model called sales_prediction as well as its first and second level children (downstream tasks).

dbt run --select sales_prediction+2

There are limitless possibilities when it comes to selecting specific resources in dbt CLI (including models, tests, seeds and snapshots).

Compurgation answered 25/1, 2023 at 17:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.