0
0
dbtdata~10 mins

How dbt works (SQL + Jinja + YAML) - Visual Walkthrough

Choose your learning style9 modes available
Concept Flow - How dbt works (SQL + Jinja + YAML)
Start: User writes YAML config
User writes SQL model with Jinja
dbt parses YAML for metadata
dbt renders SQL by processing Jinja
dbt compiles final SQL query
dbt runs SQL on database
Results stored as tables/views
User queries transformed data
dbt uses YAML for config, SQL with Jinja for models, compiles SQL, runs it on the database, and stores results.
Execution Sample
dbt
version: 2
models:
  - name: customers
    description: 'Customer data'

-- customers.sql
select * from raw.customers where active = true
This example shows YAML config for a model and a SQL file selecting active customers.
Execution Table
StepActionInputOutput/Result
1Read YAML configversion: 2 models: - name: customers description: 'Customer data'Metadata loaded: model 'customers' with description
2Read SQL model with Jinjaselect * from raw.customers where active = trueSQL template loaded
3Render Jinja in SQLSQL templateFinal SQL: select * from raw.customers where active = true
4Compile SQLFinal SQLCompiled SQL ready for execution
5Run SQL on databaseCompiled SQLData extracted: active customers
6Store resultsQuery resultsTable/view 'customers' created/updated
7User queries transformed dataTable/view 'customers'User gets filtered active customer data
💡 All steps complete, transformed data ready for use
Variable Tracker
VariableStartAfter Step 1After Step 3After Step 5Final
YAML configemptyLoaded with model metadataLoadedLoadedLoaded
SQL templateemptyLoadedRendered to final SQLRenderedRendered
Compiled SQLemptyemptyCompiled SQL readyExecuted SQLExecuted SQL
Database table/viewnonenonenoneCreated/updatedAvailable for queries
Key Moments - 3 Insights
Why does dbt use YAML files alongside SQL?
YAML files hold metadata and configuration like model names and descriptions, which dbt reads first (see execution_table step 1). This separates config from SQL logic.
What happens when dbt processes Jinja in SQL?
dbt replaces Jinja placeholders with actual values or logic before running SQL (see execution_table step 3). This lets you write dynamic SQL.
How does dbt store the results of SQL execution?
After running the compiled SQL on the database (step 5), dbt saves the results as tables or views (step 6) so you can query transformed data easily.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the output after step 3?
AFinal SQL with Jinja placeholders
BRaw YAML config loaded
CFinal SQL with Jinja rendered
DData stored in database
💡 Hint
Check the 'Output/Result' column for step 3 in the execution_table
At which step does dbt run the SQL query on the database?
AStep 4
BStep 5
CStep 2
DStep 6
💡 Hint
Look for the step mentioning 'Run SQL on database' in the execution_table
If the YAML config is missing, what will happen in the execution flow?
Adbt will not load model metadata, causing errors before SQL runs
Bdbt will run SQL without any changes
Cdbt will skip SQL rendering
Ddbt will store results without running SQL
💡 Hint
Refer to step 1 in execution_table where YAML config is loaded
Concept Snapshot
dbt workflow:
1. Write YAML for model config
2. Write SQL with Jinja templates
3. dbt reads YAML metadata
4. dbt renders SQL by processing Jinja
5. dbt compiles and runs SQL on DB
6. Results saved as tables/views
7. Query transformed data easily
Full Transcript
dbt works by combining YAML, SQL, and Jinja. First, you write YAML files to configure your models, giving names and descriptions. Then, you write SQL files that can include Jinja templates for dynamic parts. dbt reads the YAML to get metadata, then processes the SQL files by rendering the Jinja templates into final SQL queries. It compiles these queries and runs them on your database. The results are stored as tables or views. Finally, you can query these transformed tables easily. This flow separates configuration, logic, and execution cleanly.