0
0
dbtdata~20 mins

is_incremental() macro in dbt - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Incremental Model Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of is_incremental() in a full-refresh run
Consider a dbt model using the is_incremental() macro. What will be the output of the following code snippet during a full-refresh run?

select case when {{ is_incremental() }} then 'Incremental' else 'Full Refresh' end as run_type
dbt
select case when {{ is_incremental() }} then 'Incremental' else 'Full Refresh' end as run_type
AFull Refresh
BNULL
CIncremental
DSyntax Error
Attempts:
2 left
💡 Hint
Think about what is_incremental() returns when the model is run with a full-refresh flag.
data_output
intermediate
2:00remaining
Rows processed in incremental vs full-refresh runs
A dbt incremental model uses is_incremental() to insert only new rows:

select * from source_table where updated_at > (select max(updated_at) from {{ this }})

What is the expected number of rows processed during a full-refresh run compared to an incremental run?
dbt
select * from source_table where updated_at > (select max(updated_at) from {{ this }})
AFull-refresh processes all rows; incremental processes only new rows
BBoth full-refresh and incremental process all rows
CFull-refresh processes only new rows; incremental processes all rows
DNeither processes any rows
Attempts:
2 left
💡 Hint
Consider what data is available in the target table during each run type.
🔧 Debug
advanced
2:00remaining
Why does this incremental model fail on full-refresh?
This dbt model uses is_incremental() to insert new data:

select * from source_table where {{ 'true' if is_incremental() else 'false' }}

When run with full-refresh, it fails with a syntax error. Why?
dbt
select * from source_table where {{ 'true' if is_incremental() else 'false' }}
AThe macro returns NULL causing runtime error
BThe macro <code>is_incremental()</code> is undefined during full-refresh
CThe model tries to select from a non-existent table
DThe else clause outputs 'false' without a valid condition, causing SQL syntax error
Attempts:
2 left
💡 Hint
Check what the SQL looks like after macro expansion during full-refresh.
🚀 Application
advanced
3:00remaining
Using is_incremental() to update only changed rows
You want to write a dbt incremental model that updates only rows changed since the last run. Which SQL snippet correctly uses is_incremental() to achieve this?

Options:
Aselect * from source_table where updated_at &gt; (select max(updated_at) from {{ this }}) and {{ is_incremental() }}
B{% if is_incremental() %}select * from source_table where updated_at > (select max(updated_at) from {{ this }}){% else %}select * from source_table{% endif %}
Cselect * from source_table where updated_at &gt; (select max(updated_at) from {{ this }}) or not {{ is_incremental() }}
Dselect * from source_table where updated_at &gt; (select max(updated_at) from {{ this }}) if not {{ is_incremental() }} else select * from source_table
Attempts:
2 left
💡 Hint
Think about how to conditionally run different queries based on incremental or full-refresh mode.
🧠 Conceptual
expert
2:00remaining
Understanding is_incremental() behavior in dbt runs
Which statement best describes the behavior of the is_incremental() macro in dbt models?
A<code>is_incremental()</code> returns true during both incremental and full-refresh runs
B<code>is_incremental()</code> returns false only when the model is run incrementally
C<code>is_incremental()</code> returns true only when the model is run incrementally, and false during full-refresh or initial runs
D<code>is_incremental()</code> returns true only during the first run of the model
Attempts:
2 left
💡 Hint
Recall the purpose of incremental models and how dbt distinguishes run types.