Bird
0
0

Identify the error in this incremental model SQL snippet:

medium📝 Debug Q14 of 15
dbt - Incremental Models

Identify the error in this incremental model SQL snippet:

{{ config(materialized='incremental') }}

select id, updated_at, data
from source_table

{% if is_incremental() %}
  where updated_at > (select max(updated_at) from source_table)
{% endif %}
AThe filter compares <code>updated_at</code> to max from <code>source_table</code> instead of the target table.
BThe <code>is_incremental()</code> block is missing an <code>else</code> clause.
CThe model should use <code>materialized='table'</code> instead of <code>incremental</code>.
DThe <code>select</code> statement is missing a <code>group by</code> clause.
Step-by-Step Solution
Solution:
  1. Step 1: Check the incremental filter logic

    The filter uses max(updated_at) from source_table, which is the source, not the target incremental table.
  2. Step 2: Understand correct incremental filter

    The filter should compare to max(updated_at) from the target table ({{ this }}) to avoid reloading all data.
  3. Final Answer:

    The filter compares updated_at to max from source_table instead of the target table. -> Option A
  4. Quick Check:

    Incremental filter must use target table max date [OK]
Quick Trick: Use target table max date in incremental filter [OK]
Common Mistakes:
MISTAKES
  • Using source table max date in incremental filter
  • Forgetting to use {{ this }} in subquery
  • Confusing incremental and full refresh logic

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More dbt Quizzes