Recall & Review
beginner
What is a variable in dbt and how is it used?
A variable in dbt is a named value that you can set and reuse in your models or macros. It helps make your code flexible by allowing you to change values without editing the whole code.
Click to reveal answer
beginner
How do you define and use an if-else control flow in dbt?
In dbt, you use Jinja templating for control flow. An if-else looks like: {% if condition %} do something {% else %} do something else {% endif %}. It helps run different code based on conditions.
Click to reveal answer
beginner
Explain the purpose of the 'set' statement in dbt.
The 'set' statement assigns a value to a variable inside a dbt model or macro. For example, {% set my_var = 10 %} stores 10 in my_var for later use in the code.
Click to reveal answer
intermediate
What is the difference between 'if' and 'elif' in dbt control flow?
'if' starts a condition check. 'elif' (else if) checks another condition only if the previous 'if' was false. It helps check multiple conditions in order.
Click to reveal answer
intermediate
How can you use variables to make dbt models more dynamic?
You can pass variables to dbt models or macros to change behavior without changing code. For example, use a variable to filter data by date or region dynamically.
Click to reveal answer
Which syntax correctly sets a variable named 'threshold' to 100 in dbt?
✗ Incorrect
In dbt, variables are set using Jinja syntax with {% set variable = value %}.
What does the following dbt code do? {% if is_active %} SELECT * FROM users {% else %} SELECT * FROM guests {% endif %}
✗ Incorrect
The if-else block chooses the table based on the value of is_active.
How do you check multiple conditions in dbt control flow?
✗ Incorrect
dbt uses Jinja which supports if, elif, and else for multiple condition checks.
Which of these is NOT a valid way to use variables in dbt?
✗ Incorrect
Variables in dbt are set once per execution and cannot be changed dynamically during model run.
What happens if the condition in an if statement is false and there is no else block?
✗ Incorrect
If the condition is false and no else block exists, the code inside if is skipped.
Explain how variables and control flow work together in dbt to make models flexible.
Think about how you can change model behavior without rewriting code.
You got /4 concepts.
Describe a real-life example where you would use variables and if-else in a dbt model.
Imagine you want to run different queries based on user input or environment.
You got /3 concepts.