0
0
dbtdata~20 mins

How dbt works (SQL + Jinja + YAML) - Practice Exercises

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
dbt Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this Jinja expression in a dbt model?
Given the following Jinja code snippet inside a dbt SQL model, what will be the output SQL after rendering?
dbt
{% set threshold = 10 %}
SELECT * FROM sales WHERE amount > {{ threshold }}
ASELECT * FROM sales WHERE amount > 10
BSELECT * FROM sales WHERE amount > 'threshold'
CSELECT * FROM sales WHERE amount > {{ threshold }}
DSELECT * FROM sales WHERE amount > threshold
Attempts:
2 left
💡 Hint
Remember that Jinja variables inside {{ }} are replaced with their values during rendering.
data_output
intermediate
2:00remaining
What data does this dbt model produce?
Consider this dbt model SQL code using Jinja: {% raw %} SELECT user_id, COUNT(*) AS order_count FROM {{ ref('orders') }} GROUP BY user_id HAVING COUNT(*) > 5 {% endraw %} What does this model output?
dbt
SELECT user_id, COUNT(*) AS order_count
FROM orders
GROUP BY user_id
HAVING COUNT(*) > 5
AAn error because HAVING cannot be used without GROUP BY
BA table with all users and their total orders including those with 5 or fewer
CA table with orders filtered to only those with order_count > 5
DA table with users who have more than 5 orders and their order counts
Attempts:
2 left
💡 Hint
HAVING filters groups after aggregation.
🔧 Debug
advanced
3:00remaining
Why does this dbt YAML config cause an error?
Given this dbt model configuration in YAML: models: my_project: +materialized: table my_model: +tags: ['finance', 'monthly'] What is the cause of the error when running dbt?
dbt
models:
  my_project:
    +materialized: table
    my_model:
      +tags: ['finance', 'monthly']
AYAML indentation is incorrect; 'my_model' should be at the same level as '+materialized'
BThe '+materialized' config should be under 'my_model', not directly under 'my_project'
CThe '+tags' value must be a string, not a list
DThe '+' prefix is invalid in dbt YAML config keys
Attempts:
2 left
💡 Hint
Model-specific configs must be nested under the model name.
🚀 Application
advanced
2:00remaining
How does dbt handle model dependencies with ref()?
In dbt, what is the effect of using {{ ref('model_b') }} inside model_a.sql?
AIt tells dbt that model_a depends on model_b, so model_b runs first and its table/view is referenced
BIt runs model_b's SQL code inside model_a's SQL as a subquery
CIt creates a copy of model_b's data inside model_a's table
DIt causes an error if model_b does not exist in the same folder
Attempts:
2 left
💡 Hint
Think about how dbt builds the DAG of models.
🧠 Conceptual
expert
3:00remaining
What is the role of Jinja templating in dbt models?
Which statement best describes how Jinja templating works in dbt?
AJinja is used only for formatting SQL code for readability in dbt models
BJinja runs inside the database engine to optimize SQL queries at runtime
CJinja allows dynamic SQL generation by inserting variables, control flow, and macros before SQL runs in the warehouse
DJinja replaces YAML configurations with SQL code automatically
Attempts:
2 left
💡 Hint
Jinja runs before SQL is sent to the database.