Introduction

Dbt is a wide tool and there are more functionalities it has other than running models and data transformation.

Other commands

Below are some of the other commands you may work with in dbt:

  • dbt-compile - this executes the SQL from the files under the model, test and analysis folders.

The compile command is useful for:

  1. Visually inspecting the compiled output of model files. This is useful for validating complex jinja logic or macro usage.

  2. Manually running compiled SQL. While debugging a model or schema test, it’s often useful to execute the underlying select statement to find the source of the bug.

  3. Compiling analysis files.

The compiled SQL files will appear under the target/ directory.

For example, when the dbt compile command is run, the following is the output:

09:43:33  Running with dbt=1.7.14
09:43:36  Registered adapter: databricks=1.7.14
09:43:37  Found 198 models, 1 seed, 352 tests, 216 sources, 0 exposures, 0 metrics, 684 macros, 0 groups, 0 semantic models
09:43:37  
09:46:01  Concurrency: 1 threads (target='dev')

If you open the target>compiled>nip_dbt>models folder, you will find a subfolder of every model that we have developed. Notice it is only the SQL files that are found in this path, and the yml files are nowhere to be found.

Target folder

If you open one of the SQL folders, say for bronze_gem_grass_litter_subtable_grass_litter_details subtable, you will see the SQL that was run in your data warehouse. Notice it is different from the SQL models found in the src/models folder. It doesn’t have the configurations and the SQL is a bit leaner.

Target sql

If you would like to print the generated SQL on your terminal, read here.

  • dbt test - runs data tests defined on models, sources, snapshots, and seeds and unit tests defined on SQL models. It expects that you have already created those resources through the appropriate commands.