We use full refresh and incremental methods to update data efficiently. Full refresh reloads everything, while incremental updates only add new or changed data.
Full refresh vs incremental in dbt
models:
my_model:
materialized: incremental
incremental_strategy: insert_overwrite
unique_key: id
-- SQL inside the model
{{ config(materialized='incremental', unique_key='id') }}
SELECT * FROM source_table
{% if is_incremental() %}
WHERE updated_at > (SELECT MAX(updated_at) FROM {{ this }})
{% endif %}materialized: defines how dbt builds the model (table, view, incremental).
is_incremental(): lets you write SQL that runs only during incremental runs.
{{ config(materialized='table') }}
SELECT * FROM source_tableupdated_at.{{ config(materialized='incremental', unique_key='id') }}
SELECT * FROM source_table
{% if is_incremental() %}
WHERE updated_at > (SELECT MAX(updated_at) FROM {{ this }})
{% endif %}This dbt model uses incremental materialization. On first run, it loads all data. On later runs, it adds only rows with newer updated_at values.
-- dbt model: incremental_example.sql
{{ config(materialized='incremental', unique_key='id') }}
SELECT id, name, updated_at FROM source_table
{% if is_incremental() %}
WHERE updated_at > (SELECT MAX(updated_at) FROM {{ this }})
{% endif %}Full refresh rebuilds the entire table and can be slow for large data.
Incremental models need a unique key to avoid duplicates.
Use is_incremental() to write SQL that runs only during incremental updates.
Full refresh reloads all data every time.
Incremental updates add only new or changed data.
Incremental saves time and resources for large datasets.
Practice
What is the main difference between a full refresh and an incremental model in dbt?
Solution
Step 1: Understand full refresh behavior
A full refresh reloads the entire dataset, replacing all existing data.Step 2: Understand incremental behavior
An incremental model only adds or updates new or changed data, saving time.Final Answer:
Full refresh reloads all data; incremental loads only new or changed data. -> Option DQuick Check:
Full refresh = reload all, Incremental = load changes [OK]
- Confusing which method reloads all data
- Thinking incremental deletes all data first
- Assuming full refresh only runs once
Which of the following is the correct way to configure a dbt model for incremental loading?
-- model.sql
{{ config(
materialized = '???'
) }}Solution
Step 1: Identify materialization types in dbt
dbt supports 'table', 'view', 'incremental', and 'ephemeral' materializations.Step 2: Select the incremental materialization
To enable incremental loading, set materialized = 'incremental'.Final Answer:
'incremental' -> Option AQuick Check:
Incremental config = 'incremental' [OK]
- Using 'table' instead of 'incremental'
- Confusing 'view' with incremental
- Forgetting to set materialized property
Given this incremental model SQL snippet, what will happen when you run dbt run --full-refresh?
{{ config(materialized='incremental') }}
select id, updated_at, data
from source_table
{% if is_incremental() %}
where updated_at > (select max(updated_at) from {{ this }})
{% endif %}
Solution
Step 1: Understand
Running with--full-refresheffect--full-refreshforces dbt to drop and rebuild the entire incremental model.Step 2: Analyze the SQL logic
Theis_incremental()block is skipped during full refresh, so no filter applies; all rows are selected.Final Answer:
The entire table will be rebuilt fromsource_table. -> Option CQuick Check:
Full refresh rebuilds all data [OK]
- Thinking incremental filter still applies on full refresh
- Assuming model fails with is_incremental()
- Believing no data changes on full refresh
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 %}
Solution
Step 1: Check the incremental filter logic
The filter uses max(updated_at) fromsource_table, which is the source, not the target incremental table.Step 2: Understand correct incremental filter
The filter should compare to max(updated_at) from the target table ({{ this }}) to avoid reloading all data.Final Answer:
The filter comparesupdated_atto max fromsource_tableinstead of the target table. -> Option AQuick Check:
Incremental filter must use target table max date [OK]
- Using source table max date in incremental filter
- Forgetting to use {{ this }} in subquery
- Confusing incremental and full refresh logic
You have a large sales table that updates daily. You want to use dbt incremental models to update only new sales but also occasionally rebuild the entire table to fix data issues. Which approach is best?
- Use
materialized='incremental'withis_incremental()filter onsale_date. - Run
dbt rundaily for incremental updates. - Run
dbt run --full-refreshwhen you need a full rebuild.
What is the main benefit of this approach?
Solution
Step 1: Understand incremental daily updates
Using incremental materialization with a filter onsale_dateloads only new sales daily, saving time.Step 2: Understand full refresh usage
Running with--full-refreshrebuilds the entire table to fix data issues when needed.Step 3: Identify main benefit
This approach balances efficiency and data correctness by updating incrementally and allowing full rebuilds.Final Answer:
It saves time by only processing new data daily and allows full rebuilds when needed. -> Option BQuick Check:
Incremental + full refresh = efficient and flexible [OK]
- Thinking full refresh runs every day
- Believing incremental never rebuilds data
- Assuming manual data deletion is required
Ready to prove it?
Pass the test and this pattern moves unknown
