0% found this document useful (0 votes)
357 views

DBT Cheat Sheet

This document provides a cheat sheet of commands and flags for the dbt (data build tool) CLI (command line interface). It lists the main commands like dbt build, dbt run, and dbt test. It describes global CLI flags like --select and --exclude for specifying which models, seeds, snapshots, or tests to include/exclude. It also covers node selection syntax using + operators and selection methods.

Uploaded by

Christo88
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
357 views

DBT Cheat Sheet

This document provides a cheat sheet of commands and flags for the dbt (data build tool) CLI (command line interface). It lists the main commands like dbt build, dbt run, and dbt test. It describes global CLI flags like --select and --exclude for specifying which models, seeds, snapshots, or tests to include/exclude. It also covers node selection syntax using + operators and selection methods.

Uploaded by

Christo88
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

LinkedIn

Source
https://www.linkedin.com/in/
https://docs.getdbt.com/
brunoszdl/

Commands Cheat Sheet


Main commands Global CLI Flags
dbt init* Initializes a new dbt project --version* Returns
Returnsinformation
information about
about thethe currently
currently installed
installed
versionofofdbt.
version dbt.
dbt build Builds and tests all selected resources (models,
seeds, snapshots, tests) Savesperformance
--record-timing-info* Saves performance profiling
profiling information
information to a file
to a file

dbt clean* Deletes artifacts present in the dbt project *CLI Only*CLI Only

dbt compile Compiles (but does not run) the models in a project

dbt debug* Debugs dbt connections and projects Other flags


dbt deps Downloads dependencies for a project
--help Shows available commands and arguments
dbt docs Generates documentation for a Project
--vars Supplies variables to the project
dbt list* Lists resources defined in a dbt project
-- full-refresh Drops existing tables and recreates them
dbt parse* Parses a project and writes detailed timing info
--fail-fast Enforces a dbt run/test to end up on first error/test
dbt run Runs the models in a project failure

dbt seed Loads CSV files into the database --threads Specifies the number of threads to use while
executing models
dbt snapshot Executes "snapshot" jobs defined in a project

dbt source Provides tools for working with source data


(including validating that sources are "fresh") dbt docs
dbt test Executes tests defined in a project
generate Generates your projects’s documentation website.
Use the –no-compile argument to skip re-compilation
dbt rpc* Runs an RPC server that clients can submit queries to
serve Starts a webserver on port 8000 to serve your
dbt run-operation Runs arbitrary maintenance SQL against the database
documentation locally
*CLI Only

Node selection
Syntax overview Specifying resources
The –select flag accepts one or more arguments. Each argument can be one
command arguments of compatibility.
• A packages name
run --select (-s), --exclude, --selector, --defer • A model name
• A fully-qualified path to a directory of models
test --select (-s), --exclude, --selector, --defer • A selection method (path:, tag:, config:, test_type:, test_name:)
Examples:
seed --select (-s), --exclude, --selector • $ dbt run --select my_dbt_project_name - all models in your project
• $ dbt run --select my_dbt_model - a specific model
• $ dbt run --select path.to.my.models - all models in a specific directory
snapshot --select (-s), --exclude, --selector • $ dbt run --select tag:nightly - models with the "nightly" tag
• $ dbt run --select path/to/models - models contained in path/to/models
list --select (-s), --exclude, --selector, --resource-type • $ dbt test --select test_type:generic - run all generic tests
• $ dbt test --select test_type:singular - run all singular tests
compile --select (-s), --exclude, --selector • $ dbt test --select test_name:unique - run all instances of the `unique` test

freshness --select (-s), --exclude, --selector Excluding models


dbt provides an –exclude flag with the same semantics as –select. Models specified
build --select (-s), --exclude, --selector, --resource-type, --defer
with the –exclude flag will be removed from the set of models selected with –select.
In earlier versions, the flag --models (-m) was used instead of –select. Those
Example:
commands still support the –models flag for backwards compatibility.
• $ dbt run --select my_package.*+ --exclude my_package.a_big_model+

Graph operators Methods


Plus operator(+)
• $ dbt run --select my_model+ - select my_model and all children
• $ dbt run --select +my_model - select my_model and all parents
• $ dbt run --select +my_model+ - select my_model, and all of its parents and children
tag source path
N-plus operator
• $ dbt run --select my_model+1 - select my_model and its first-degree children
• $ dbt run --select 2+my_model - select my_model, its first-degree parents, and its package config test_type
second-degree parents ("grandparents")
• $ dbt run --select 3+my_model+4 - select my_model, its parents up to the 3rd degree, and
its children down to the 4th degree test_name state exposure

At operator(@)
• $ dbt run --models @my_model - select my_model, its children, and the parents of its metric result source_status
children

Star operator(*)
• $ dbt run --select finance.base.* - run all of the models in models/finance/base

Set operators
Unions (space-delineated)
• $ dbt run --select +snowplow_sessions +fct_orders - run snowplow_sessions, all ancestors of snowplow_sessions, fct_orders, and all ancestors of fct_orders)

Intersections (comma-separated) – must meet all conditions


• $ dbt run --select +snowplow_sessions,+fct_orders - run all the common ancestors of snowplow_sessions and fct_orders
• $ dbt run --select marts.finance,tag:nightly - run models that are in the marts/finance subdirectory and tagged nightly, simultaneously
• $ dbt test --select +fct_orders,test_type:generic - run generic tests of fct_orders and its ancestors

You might also like