Executing Incremental dbt Models
Lab Steps
Introduction
In this lab step, you will execute the dbt models you previously defined and check that the tables are incrementally loaded.
Â
Instructions
1. Open the terminal by clicking on Terminal -> New Terminal:
Â
2. Move into the dbt project folder by entering the following command:
Copy code
1
cd ca_dbt_project
Â
3. Execute the following command to build the dbt project:
Copy code# The export command is needed to let dbt know the profiles file is in the current directory export DBT_PROFILES_DIR='.' dbt run
After a few seconds, dbt will complete the execution with an output similar to the following:
As you can see from the logs, dbt has built both the models you defined and also the models that were already in the lab environment.
Â
4. Execute the following command to log into the database:
Copy code
1
psql -U postgres -d ca_dbt
Â
5. Enter the following SQL query to retrieve the last 10 rows in the f_orders table:
Copy code
1
select * from dbt_outputs.f_orders order by order_id desc limit 10;
Â
6. Enter the following command to add a new record to the orders source table:
Copy code
1
insert into public.orders values (30000, 'TOMSP', 6, '2022-07-10', '2022-07-13', '2022-07-11', 1, 11.56);
Â
7. Exit from the database terminal by entering CTRL + Z, and perform dbt execution again by enetring the following command:
Copy code
1
dbt run
As you can see from the last two logs, dbt hasn't performed a select in order to create a new table as it did previously, but it performed an insert.
Â
8. Enter again in the database by executing the psql -U postgres -d ca_dbt
 command, and execute the SQL query to check that the new record has been added:
Copy code
1
select * from dbt_outputs.f_orders order by order_id desc limit 10;
As you can see the new record has been added to the table.
Â
Summary
In this lab step, you executed the dbt models you previously defined and checked that the tables are incrementally loaded.
Check whether the dbt models have been executed.