2. Run your project
Now that we have a dbt project with some models and tests, we can run the project locally to see if everything is working as expected. We are using Duckdb in this example, which is an in-memory database and thus we do not need to setup a database.
2.1 Run one model
If you use a configured dbt base image or the custom provided ide.yaml when creating your project, you can run one model by clicking ctrl+enter.
In order for the shortcut to work you must be editing the file sql file. Click on one of the files and make sure your cursor is shown in the SQL file.
This functionality is provided by the vscode-dbt-power-user
extension of vscode. The plugin can do a lot more: autocomplete dbt code, show lineage, ...
For more information look here.
2.2 Run all the dbt models
If you want to run all your dbt models in the project, you can do that using the terminal. Click on the button in the top left corner of VSCode, containing 3 lines, and then select terminal -> New Terminal. You can run the dbt models by executing the following command:
dbt run
The duckdb
database runs in-memory but it is also persisted to disk in the workspace/dbt.duckdb
file in the root of your project.
To show the state of your database after running your models, you can execute the following python script python3 query_duckdb.python
.
Apart from running the dbt models, you can also execute the tests from within the shell by using the dbt test
command.
The output of dbt test shows that there is something wrong with the code, which is what we will fix in the next section.
2.3 Fix the dbt code
The output of one of the models is not returning the expected results, can you figure out what is wrong in the respective sql file?
If you do not see it, look at the comment in the my_first_dbt_model.sql
file for a hint.
After fixing the model, run:
dbt build
Now you should see that the all models run correctly and the tests pass.