0
0
dbtdata~20 mins

Materializations (view, table, incremental, ephemeral) in dbt - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Materialization Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of a view materialization in dbt

Given the following dbt model configured as a view, what will be the result when querying the model?

-- models/my_view.sql
{{ config(materialized='view') }}

select
  user_id,
  count(*) as total_orders
from {{ ref('orders') }}
group by user_id

Assume the orders table has 3 users with 2, 3, and 5 orders respectively.

ANo table or view is created; the model runs only during compilation and returns no data.
BA physical table is created with the aggregated data, so querying my_view returns 0 rows until manually refreshed.
CAn incremental table is created that only updates new orders, so querying my_view returns partial data until full refresh.
DA view is created that runs the query fresh each time, so querying my_view returns 3 rows with counts 2, 3, and 5.
Attempts:
2 left
💡 Hint

Think about what a view materialization does in dbt.

data_output
intermediate
2:00remaining
Rows in a table materialization after multiple runs

Consider a dbt model configured as a table materialization:

-- models/my_table.sql
{{ config(materialized='table') }}

select * from {{ ref('customers') }}

If the customers table has 100 rows, and you run dbt run twice, how many rows will my_table contain after the second run?

A100 rows, because the table is dropped and recreated each run.
B200 rows, because the data is appended each run.
C0 rows, because the table is not created automatically.
D100 rows, but only if you run dbt seed first.
Attempts:
2 left
💡 Hint

Think about how dbt handles table materializations on multiple runs.

🔧 Debug
advanced
3:00remaining
Why does incremental model not update all rows?

You have this incremental model:

-- models/incremental_orders.sql
{{ config(materialized='incremental', unique_key='order_id') }}

select * from {{ ref('orders') }}
{% if is_incremental() %}
  where order_date > (select max(order_date) from {{ this }})
{% endif %}

After running dbt multiple times, you notice some orders with earlier dates are missing in incremental_orders. Why?

ABecause the incremental filter only adds rows with order_date greater than max in the table, older rows are never added or updated.
BBecause the model is configured as a view, incremental logic is ignored.
CBecause the unique_key is wrong, dbt cannot merge rows correctly.
DBecause dbt does not support incremental models with date filters.
Attempts:
2 left
💡 Hint

Look at the filter condition inside is_incremental().

🧠 Conceptual
advanced
2:00remaining
Purpose of ephemeral materialization in dbt

What is the main purpose of using ephemeral materialization in dbt models?

ATo create temporary tables in the database that persist only during the session.
BTo inline the model SQL into downstream models without creating any physical table or view.
CTo create views that refresh automatically on each query.
DTo create incremental tables that update only new data.
Attempts:
2 left
💡 Hint

Think about how ephemeral models behave in dbt compilation.

🚀 Application
expert
4:00remaining
Choosing materialization for a large slowly changing dataset

You have a large dataset of customer transactions that updates daily with new rows and occasional corrections to existing rows. You want to build a dbt model that efficiently updates only new and changed rows without rebuilding the entire dataset each run. Which materialization should you choose and why?

AUse <code>table</code> materialization because it rebuilds the entire dataset ensuring correctness.
BUse <code>view</code> materialization because it always shows the latest data without storage cost.
CUse <code>incremental</code> materialization with a unique key and logic to update changed rows efficiently.
DUse <code>ephemeral</code> materialization to inline the logic and avoid physical tables.
Attempts:
2 left
💡 Hint

Consider the trade-offs between full rebuilds and incremental updates for large datasets.