About dbt build command
The dbt build command will:
- run models
- test tests
- snapshot snapshots
- seed seeds
- run user-defined functions (available from dbt Core v1.11 and in the dbt Fusion Engine)
In DAG order, for selected resources or an entire project.
Details
Artifacts: The build task will write a single manifest and a single run results artifact. The run results will include information about all models, tests, seeds, and snapshots that were selected to build, combined into one file.
Skipping on failures: Tests on upstream resources will block downstream resources from running, and a test failure will cause those downstream resources to skip entirely. E.g. If model_b depends on model_a, and a unique test on model_a fails, then model_b will SKIP.
- Don't want a test to cause skipping? Adjust its severity or thresholds to
warninstead oferror - In the case of a test with multiple parents, where one parent depends on the other (e.g. a
relationshipstest betweenmodel_a+model_b), that test will block-and-skip children of the most-downstream parent only (model_b).
Selecting resources: The build task supports standard selection syntax (--select, --exclude, --selector), as well as a --resource-type flag that offers a final filter (just like list). Whichever resources are selected, those are the ones that build will run/test/snapshot/seed.
- Remember that tests support indirect selection, so
dbt build -s model_awill both run and testmodel_a. What does that mean? Any tests that directly depend onmodel_awill be included, so long as those tests don't also depend on other unselected parents. See test selection for details and examples.
Flags: The build task supports all the same flags as run, test, snapshot, and seed. For flags that are shared between multiple tasks (e.g. --full-refresh), build will use the same value for all selected resource types (e.g. both models and seeds will be full refreshed).
The --empty flag
The build command supports the --empty flag for building schema-only dry runs. The --empty flag limits the refs and sources to zero rows. dbt will still execute the model SQL against the target data warehouse but will avoid expensive reads of input data. This validates dependencies and ensures your models will build properly.
The render method
The .render() method is generally used to resolve or evaluate Jinja expressions (such as {{ source(...) }}) during runtime.
When using the --empty flag, dbt may skip processing ref() or source() for optimization. To avoid compilation errors and to explicitly tell dbt to process a specific relation (ref() or source()), use the .render() method in your model file. For example:
{{ config(
pre_hook = [
"alter external table {{ source('sys', 'customers').render() }} refresh"
]
) }}
select ...
Tests
When dbt build is executed with unit tests applied, the models will be processed according to their lineage and dependencies. The tests will be executed as follows:
- Unit tests are run on a SQL model.
- The model is materialized.
- Data tests are run on the model.
This saves on warehouse spend as the model will only be materialized if the unit tests pass successfully.
Unit tests and data tests can be selected using --select test_type:unit or --select test_type:data for dbt build (same for the --exclude flag).
Examples
$ dbt build
Running with dbt=1.9.0-b2
Found 1 model, 4 tests, 1 snapshot, 1 analysis, 341 macros, 0 operations, 1 seed file, 2 sources, 2 exposures
18:49:43 | Concurrency: 1 threads (target='dev')
18:49:43 |
18:49:43 | 1 of 7 START seed file dbt_jcohen.my_seed............................ [RUN]
18:49:43 | 1 of 7 OK loaded seed file dbt_jcohen.my_seed........................ [INSERT 2 in 0.09s]
18:49:43 | 2 of 7 START view model dbt_jcohen.my_model.......................... [RUN]
18:49:43 | 2 of 7 OK created view model dbt_jcohen.my_model..................... [CREATE VIEW in 0.12s]
18:49:43 | 3 of 7 START test not_null_my_seed_id................................ [RUN]
18:49:43 | 3 of 7 PASS not_null_my_seed_id...................................... [PASS in 0.05s]
18:49:43 | 4 of 7 START test unique_my_seed_id.................................. [RUN]
18:49:43 | 4 of 7 PASS unique_my_seed_id........................................ [PASS in 0.03s]
18:49:43 | 5 of 7 START snapshot snapshots.my_snapshot.......................... [RUN]
18:49:43 | 5 of 7 OK snapshotted snapshots.my_snapshot.......................... [INSERT 0 5 in 0.27s]
18:49:43 | 6 of 7 START test not_null_my_model_id............................... [RUN]
18:49:43 | 6 of 7 PASS not_null_my_model_id..................................... [PASS in 0.03s]
18:49:43 | 7 of 7 START test unique_my_model_id................................. [RUN]
18:49:43 | 7 of 7 PASS unique_my_model_id....................................... [PASS in 0.02s]
18:49:43 |
18:49:43 | Finished running 1 seed, 1 view model, 4 tests, 1 snapshot in 1.01s.
Completed successfully
Done. PASS=7 WARN=0 ERROR=0 SKIP=0 TOTAL=7
Functions
Available from dbt Core v1.11 and in the dbt Fusion Engine
The build command runs user-defined functions as part of the DAG execution. To build or rebuild only functions in your project, run dbt build --select "resource_type:function". For example:
dbt build --select "resource_type:function"
dbt-fusion 2.0.0-preview.45
Succeeded [ 0.98s] function dbt_schema.whoami (function)
Succeeded [ 1.12s] function dbt_schema.area_of_circle (function)
Was this page helpful?
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.