0
0
dbtdata~30 mins

How dbt works (SQL + Jinja + YAML) - Try It Yourself

Choose your learning style9 modes available
How dbt works (SQL + Jinja + YAML)
📖 Scenario: You are working as a data analyst in a company that uses dbt (data build tool) to transform raw data into clean, usable tables for reporting. You want to understand how dbt combines SQL, Jinja templating, and YAML configuration to build data models step-by-step.
🎯 Goal: Build a simple dbt model using SQL with Jinja templating and configure it with YAML. You will create a source table, add a configuration variable, write a SQL model using Jinja, and finally display the compiled SQL output.
📋 What You'll Learn
Create a source table dictionary in YAML format
Add a configuration variable for filtering data
Write a SQL model using Jinja templating to filter data based on the config variable
Print the final compiled SQL query as output
💡 Why This Matters
🌍 Real World
dbt is widely used in data teams to manage and transform data in a clear, version-controlled way. Understanding how SQL, Jinja, and YAML work together helps you build reliable data models.
💼 Career
Data analysts and engineers use dbt to create clean datasets for reporting and analysis. Knowing how to write dbt models and configurations is a valuable skill in modern data roles.
Progress0 / 4 steps
1
Create a source table configuration in YAML
Create a YAML string variable called source_yaml that defines a source named raw_data with a table named users. The table should have columns id, name, and age.
dbt
Need a hint?

Use triple quotes to create a multi-line YAML string. Follow the indentation exactly as shown.

2
Add a configuration variable for filtering age
Create a variable called min_age and set it to 18. This will be used to filter users who are at least 18 years old.
dbt
Need a hint?

Just assign the number 18 to the variable named min_age.

3
Write a SQL model using Jinja templating to filter users by age
Create a string variable called model_sql that contains a SQL query using Jinja templating. The query should select id, name, and age from {{ source('raw_data', 'users') }} where age >= {{ min_age }}.
dbt
Need a hint?

Use triple quotes for the SQL string. Use Jinja syntax with double curly braces for source and min_age.

4
Print the compiled SQL query
Write a print statement to display the model_sql string.
dbt
Need a hint?

Use print(model_sql) to display the SQL string.