Node Selection Syntax
When you run dbt build, dbt executes every single model, seed, snapshot, and test in your entire project.
If you work at an enterprise company in Bengaluru with 2,000 models, running dbt build will take hours and cost thousands of dollars in Snowflake credits.
As a Data Engineer, you must know how to precisely execute only the specific slice of the Directed Acyclic Graph (DAG) that you care about. We do this using Node Selection Syntax via the --select and --exclude flags.
Topics Covered
- Direct Selection
- Graph Operators (Upstream & Downstream)
- Intersections and Exclusions
- Selecting by Path and Tag
1. Direct Selection
The most basic way to select a model is by its exact name.
# Run exactly one model
dbt run --select stg_customers
# Run multiple specific models (space-separated)
dbt run --select stg_customers fct_orders
2. Graph Operators (The '+' Sign)
The true power of dbt is its knowledge of dependencies (the DAG). You can use the + operator to traverse the graph.
Upstream Parents (+model)
If a model is broken, you often want to rebuild it and all the staging tables that feed into it. Place the + before the model name.
# "Run fct_orders, AND all of its upstream parents"
dbt run --select +fct_orders
Downstream Children (model+)
If you add a new column to a staging table, you want to rebuild it and all the downstream dashboards that rely on it. Place the + after the model name.
# "Run stg_customers, AND all of its downstream children"
dbt run --select stg_customers+
Both Upstream & Downstream (+model+)
If you want to run the entire lineage path for a specific model, from the raw source all the way to the final dashboards, place the + on both sides.
# "Run fct_orders, its parents, AND its children"
dbt run --select +fct_orders+
3. Selecting by Method (Tags and Paths)
You don't have to select models by their SQL filename. You can use methods.
Selecting by Directory Path
If the marketing team wants to refresh their specific models, you can run an entire directory at once.
# Run all models inside the marketing folder
dbt run --select path:models/marts/marketing
Selecting by Tag
If you tagged certain models as nightly_batch or hourly_refresh in your YAML files, you can execute them together, even if they live in completely different folders!
# Run all models that have the 'hourly_refresh' tag
dbt run --select tag:hourly_refresh
4. Intersections and Exclusions
You can combine selectors to be incredibly precise.
Intersections (The ',' comma operator)
A comma acts as an AND operator.
# "Run models that are in the marketing folder AND have the tag 'hourly'"
dbt run --select path:models/marts/marketing,tag:hourly
Exclusions (--exclude)
You can use the --exclude flag to remove specific nodes from your selection.
Imagine you want to run the entire finance folder, but there is one massive historical model (fct_10_year_ledger) that takes 3 hours to build, and you want to skip it today.
# Run the finance folder, but skip the massive ledger model
dbt run --select path:models/marts/finance --exclude fct_10_year_ledger
Summary
- Node Selection allows you to execute precise slices of your DAG to save compute time and money.
- Use
+modelto run upstream parents, andmodel+to run downstream children. - Use
path:andtag:to select models by directory or metadata. - Use the
--excludeflag to remove specific expensive or broken models from your execution.