Skip to main content

Example usage for dbt State Preview

These examples use the Jaffle Shop project to show side-by-side comparisons of CLI output with and without dbt State enabled.

The following examples use this Jaffle Shop project DAG as a reference. You can refer to it to understand the model lineage for each scenario.

The Jaffle Shop DAGThe Jaffle Shop DAG

Each of the following scenarios shows how a run differs between dbt Core alone and dbt Core with dbt State, using the same command and project.

ScenarioCommandWhat dbt State changes
Initial run in empty schemadbt run --target prodSame result
Second rundbt run --target prodSkips unchanged nodes
Selecting a model in a fresh dev environment after changing the customers modeldbt run --target dev --select "customers"Defers to prod for upstream models
Selecting a model in a new dev schema with no model changesdbt run --target dev --select "customers"Defers and clones unchanged models
Loading table...

Initial run in empty schema

dbt run --target prod

You get the same result with and without dbt State.

Running with dbt=1.12.0-b2
Registered adapter: snowflake=1.11.5
Found 12 models, 6 seeds, 27 data tests, 6 sources, 644 macros, 3 unit tests

Concurrency: 1 threads (target='prod')

1 of 12 START sql view model jaffle_analytics.stg_customers .................... [RUN]
1 of 12 OK created sql view model jaffle_analytics.stg_customers ............... [SUCCESS 1 in 0.54s]
2 of 12 START sql view model jaffle_analytics.stg_locations .................... [RUN]
2 of 12 OK created sql view model jaffle_analytics.stg_locations ............... [SUCCESS 1 in 0.48s]
3 of 12 START sql view model jaffle_analytics.stg_order_items .................. [RUN]
3 of 12 OK created sql view model jaffle_analytics.stg_order_items ............. [SUCCESS 1 in 0.51s]
4 of 12 START sql view model jaffle_analytics.stg_orders ....................... [RUN]
4 of 12 OK created sql view model jaffle_analytics.stg_orders .................. [SUCCESS 1 in 0.77s]
5 of 12 START sql view model jaffle_analytics.stg_products ..................... [RUN]
5 of 12 OK created sql view model jaffle_analytics.stg_products ................ [SUCCESS 1 in 0.58s]
6 of 12 START sql view model jaffle_analytics.stg_supplies ..................... [RUN]
6 of 12 OK created sql view model jaffle_analytics.stg_supplies ................ [SUCCESS 1 in 0.63s]
7 of 12 START sql table model jaffle_analytics.locations ....................... [RUN]
7 of 12 OK created sql table model jaffle_analytics.locations .................. [SUCCESS 1 in 1.81s]
8 of 12 START sql table model jaffle_analytics.products ........................ [RUN]
8 of 12 OK created sql table model jaffle_analytics.products ................... [SUCCESS 1 in 1.33s]
9 of 12 START sql table model jaffle_analytics.order_items ..................... [RUN]
9 of 12 OK created sql table model jaffle_analytics.order_items ................ [SUCCESS 1 in 2.09s]
10 of 12 START sql table model jaffle_analytics.supplies ....................... [RUN]
10 of 12 OK created sql table model jaffle_analytics.supplies .................. [SUCCESS 1 in 1.26s]
11 of 12 START sql table model jaffle_analytics.orders ......................... [RUN]
11 of 12 OK created sql table model jaffle_analytics.orders .................... [SUCCESS 1 in 1.70s]
12 of 12 START sql table model jaffle_analytics.customers ...................... [RUN]
12 of 12 OK created sql table model jaffle_analytics.customers ................. [SUCCESS 1 in 1.77s]

Finished running 6 table models, 6 view models in 0 hours 0 minutes and 17.77 seconds (17.77s).

Completed successfully

Done. PASS=12 WARN=0 ERROR=0 SKIP=0 NO-OP=0 TOTAL=12

Second run

dbt run --target prod

With dbt State enabled, dbt detects that these models just ran and that neither the models nor the source data changed, so it skips unnecessary work.

Running with dbt=1.12.0-b2
Registered adapter: snowflake=1.11.5
Found 12 models, 6 seeds, 27 data tests, 6 sources, 644 macros, 3 unit tests

Concurrency: 1 threads (target='prod')

1 of 12 START sql view model jaffle_analytics.stg_customers .................... [RUN]
1 of 12 OK created sql view model jaffle_analytics.stg_customers ............... [SUCCESS 1 in 0.54s]
2 of 12 START sql view model jaffle_analytics.stg_locations .................... [RUN]
2 of 12 OK created sql view model jaffle_analytics.stg_locations ............... [SUCCESS 1 in 0.48s]
3 of 12 START sql view model jaffle_analytics.stg_order_items .................. [RUN]
3 of 12 OK created sql view model jaffle_analytics.stg_order_items ............. [SUCCESS 1 in 0.51s]
4 of 12 START sql view model jaffle_analytics.stg_orders ....................... [RUN]
4 of 12 OK created sql view model jaffle_analytics.stg_orders .................. [SUCCESS 1 in 0.77s]
5 of 12 START sql view model jaffle_analytics.stg_products ..................... [RUN]
5 of 12 OK created sql view model jaffle_analytics.stg_products ................ [SUCCESS 1 in 0.58s]
6 of 12 START sql view model jaffle_analytics.stg_supplies ..................... [RUN]
6 of 12 OK created sql view model jaffle_analytics.stg_supplies ................ [SUCCESS 1 in 0.63s]
7 of 12 START sql table model jaffle_analytics.locations ....................... [RUN]
7 of 12 OK created sql table model jaffle_analytics.locations .................. [SUCCESS 1 in 1.81s]
8 of 12 START sql table model jaffle_analytics.products ........................ [RUN]
8 of 12 OK created sql table model jaffle_analytics.products ................... [SUCCESS 1 in 1.33s]
9 of 12 START sql table model jaffle_analytics.order_items ..................... [RUN]
9 of 12 OK created sql table model jaffle_analytics.order_items ................ [SUCCESS 1 in 2.09s]
10 of 12 START sql table model jaffle_analytics.supplies ....................... [RUN]
10 of 12 OK created sql table model jaffle_analytics.supplies .................. [SUCCESS 1 in 1.26s]
11 of 12 START sql table model jaffle_analytics.orders ......................... [RUN]
11 of 12 OK created sql table model jaffle_analytics.orders .................... [SUCCESS 1 in 1.70s]
12 of 12 START sql table model jaffle_analytics.customers ...................... [RUN]
12 of 12 OK created sql table model jaffle_analytics.customers ................. [SUCCESS 1 in 1.77s]

Finished running 6 table models, 6 view models in 0 hours 0 minutes and 17.77 seconds (17.77s).

Completed successfully

Done. PASS=12 WARN=0 ERROR=0 SKIP=0 NO-OP=0 TOTAL=12

Selecting a model in a fresh dev environment after changing the customers model

dbt run --target dev --select "customers"

Imagine you've made a small change to the customers model and run it in a fresh developer schema. Without dbt State, dbt Core fails because upstream relations are missing. With dbt State, dbt defers to prod for upstream models and runs only the updated customers model.

Running with dbt=1.12.0-b2
Registered adapter: snowflake=1.11.5
Found 12 models, 6 seeds, 27 data tests, 6 sources, 658 macros, 3 unit tests

Concurrency: 1 threads (target='dev')

1 of 1 START sql table model dbt_schema.customers .............................. [RUN]
1 of 1 ERROR creating sql table model dbt_schema.customers ..................... [ERROR in 0.36s]

Finished running 1 table model in 0 hours 0 minutes and 5.11 seconds (5.11s).

Completed with 1 error, 0 partial successes, and 0 warnings:

[ERROR]: in model customers (models/marts/customers.sql)
Database Error in model customers (models/marts/customers.sql)
002003 (42S02): SQL compilation error:
Object 'ANALYTICS.DBT_SCHEMA.STG_CUSTOMERS' does not exist or not authorized.
compiled code at target/run/jaffle_shop/models/marts/customers.sql

compiled code at target/compiled/jaffle_shop/models/marts/customers.sql

Done. PASS=0 WARN=0 ERROR=1 SKIP=0 NO-OP=0 REUSED=0 TOTAL=1

Selecting a model in a new dev schema with no model changes

dbt run --target dev --select "customers"

Suppose you create a fresh dev schema and run only the customers model. Without dbt State, dbt Core fails because there is no data in the schema. With dbt State, dbt knows customers just ran in another schema: it defers to prod for upstream models and clones customers because the outcome is unchanged.

Running with dbt=1.12.0-b2
Registered adapter: snowflake=1.11.5
Found 12 models, 6 seeds, 27 data tests, 6 sources, 658 macros, 3 unit tests

Concurrency: 1 threads (target='dev')

1 of 1 START sql table model dbt_schema.customers .............................. [RUN]
1 of 1 ERROR creating sql table model dbt_schema.customers ..................... [ERROR in 0.36s]

Finished running 1 table model in 0 hours 0 minutes and 5.11 seconds (5.11s).

Completed with 1 error, 0 partial successes, and 0 warnings:

[ERROR]: in model customers (models/marts/customers.sql)
Database Error in model customers (models/marts/customers.sql)
002003 (42S02): SQL compilation error:
Object 'ANALYTICS.DBT_SCHEMA.STG_CUSTOMERS' does not exist or not authorized.
compiled code at target/run/jaffle_shop/models/marts/customers.sql

compiled code at target/compiled/jaffle_shop/models/marts/customers.sql

Done. PASS=0 WARN=0 ERROR=1 SKIP=0 NO-OP=0 REUSED=0 TOTAL=1

Was this page helpful?

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

0
Loading