0
0
dbtdata~20 mins

Incremental strategies (append, merge, delete+insert) in dbt - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Incremental Mastery in dbt
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding Append Incremental Strategy

In dbt, the append incremental strategy adds new rows to the target table without modifying existing rows. Which of the following statements best describes a limitation of using the append strategy?

AIt cannot update existing rows if source data changes, leading to potential duplicates.
BIt deletes all rows before inserting new data, causing longer run times.
CIt merges rows based on a unique key, updating existing records automatically.
DIt requires manual deletion of old data before each run to avoid duplicates.
Attempts:
2 left
💡 Hint

Think about what happens if a row changes in the source after it was already appended.

Predict Output
intermediate
2:00remaining
Output of a Merge Incremental Model

Consider a dbt incremental model using the merge strategy with a unique key id. The source table has rows:

id | value
1  | 100
2  | 200
3  | 300

The target table initially has:

id | value
1  | 90
2  | 200

After running the incremental model, what will be the content of the target table?

dbt
merge into target_table using source_table on target_table.id = source_table.id
when matched then update set target_table.value = source_table.value
when not matched then insert (id, value) values (source_table.id, source_table.value);
A[{'id': 1, 'value': 90}, {'id': 2, 'value': 200}]
B[{'id': 1, 'value': 90}, {'id': 2, 'value': 200}, {'id': 3, 'value': 300}]
C[{'id': 1, 'value': 100}, {'id': 2, 'value': 200}]
D[{'id': 1, 'value': 100}, {'id': 2, 'value': 200}, {'id': 3, 'value': 300}]
Attempts:
2 left
💡 Hint

Remember that merge updates matching rows and inserts new ones.

data_output
advanced
2:00remaining
Result of Delete+Insert Incremental Strategy

A dbt incremental model uses the delete+insert strategy to refresh data for a specific date partition. The source data for date '2024-06-01' has 3 rows. The target table initially has 5 rows for that date. After running the model, how many rows for '2024-06-01' will the target table have?

A3
B5
C0
D8
Attempts:
2 left
💡 Hint

Delete+insert removes old rows for the partition before inserting new ones.

🔧 Debug
advanced
2:00remaining
Identify the Error in Incremental Merge SQL

Review this dbt incremental merge SQL snippet:

merge into target_table t
using source_table s
on t.id = s.id
when matched then update set value = s.value
when not matched then insert (id, value) values (s.id, s.value)

What is the error in this code?

AUsing 'update set' instead of 'update set column = value'.
BMissing closing parenthesis in the insert values clause.
CMissing semicolon at the end of the statement.
DIncorrect alias usage for source_table.
Attempts:
2 left
💡 Hint

Check the parentheses carefully in the insert statement.

🚀 Application
expert
3:00remaining
Choosing the Best Incremental Strategy for Slowly Changing Data

You manage a sales data table that updates daily. Some rows may change values (like price) after initial insert. You want to keep the target table accurate without full reloads. Which incremental strategy is best?

AAppend strategy, because it is fastest and adds new rows only.
BDelete+insert strategy, because it deletes all data and reloads fresh.
CMerge strategy, because it updates existing rows and inserts new ones.
DNo incremental strategy; always do full reloads to ensure accuracy.
Attempts:
2 left
💡 Hint

Think about how to update existing rows efficiently.