0
0
dbtdata~20 mins

Built-in Jinja context variables in dbt - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Jinja Context Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of Jinja variable usage in dbt model
What is the output of this Jinja snippet in a dbt model if the model name is sales_summary?
dbt
{% set model_name = this.name %}
{{ model_name }}
ANone
Bthis.name
C{{ this.name }}
Dsales_summary
Attempts:
2 left
💡 Hint
The this variable refers to the current model's context.
data_output
intermediate
2:00remaining
Using var to pass variables in dbt
Given the dbt model code below, what will be the output of {{ var('region', 'all') }} if no variable region is passed during runtime?
dbt
{{ var('region', 'all') }}
Aall
Bregion
CNone
DError: variable not found
Attempts:
2 left
💡 Hint
The var function returns the default value if the variable is not set.
🧠 Conceptual
advanced
2:00remaining
Purpose of config in dbt Jinja context
Which of the following best describes the purpose of the config variable in dbt's Jinja context?
AIt contains the database connection credentials.
BIt stores the runtime environment variables for the dbt project.
CIt allows setting model-specific configurations like materialization and tags.
DIt holds the compiled SQL code of the model.
Attempts:
2 left
💡 Hint
Think about how you customize model behavior in dbt.
🔧 Debug
advanced
2:00remaining
Error caused by misuse of this in dbt model
What error will occur if you try to access this.database in a dbt model when the database is not defined in the profile?
dbt
{{ this.database }}
ANone (outputs empty string)
BUndefinedError: 'database' is not defined on 'this'
CRuntimeError: Database connection failed
DKeyError: 'database'
Attempts:
2 left
💡 Hint
Check what happens when a property is missing in Jinja context.
🚀 Application
expert
3:00remaining
Using run_started_at for incremental models
You want to filter rows in an incremental dbt model to only include data updated after the current run started. Which Jinja variable should you use in your SQL WHERE clause?
Arun_started_at
Bthis.schema
Ctarget.name
Dinvocation_id
Attempts:
2 left
💡 Hint
This variable holds the timestamp when the dbt run began.