Bird
Raised Fist0
dbtdata~20 mins

Staging, intermediate, and marts pattern in dbt - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Master of Staging, Intermediate, and Marts Pattern
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Purpose of the Staging Layer in dbt

In the Staging, intermediate, and marts pattern used in dbt, what is the main purpose of the staging layer?

ATo clean and standardize raw source data for easier use in later models
BTo create final business reports and dashboards directly from raw data
CTo aggregate data into summary tables for quick analysis
DTo store backup copies of raw data without transformation
Attempts:
2 left
💡 Hint

Think about what you do first when you get messy data from different sources.

❓ Predict Output
intermediate
2:00remaining
Output of a dbt Model SQL Query in the Intermediate Layer

Given this dbt model SQL in the intermediate layer:

select
  user_id,
  count(order_id) as total_orders
from {{ ref('stg_orders') }}
group by user_id

What will be the output schema of this model?

dbt
select
  user_id,
  count(order_id) as total_orders
from {{ ref('stg_orders') }}
group by user_id
AColumns: user_id (int), total_orders (int) with one row per order
BColumns: order_id (int), total_orders (int) with one row per order
CColumns: user_id (int), total_orders (int) with one row per user
DColumns: user_id (int), order_id (int) with one row per order
Attempts:
2 left
💡 Hint

Look at the GROUP BY clause and the aggregation function.

❓ data_output
advanced
2:00remaining
Resulting DataFrame Shape After Running a Mart Model

Consider a mart model that joins the intermediate user orders model with a user demographics model on user_id. If the intermediate model has 1000 users and the demographics model has 950 users, what is the number of rows in the resulting mart model after an inner join?

A1000 rows, because all users from the intermediate model are kept
B50 rows, because only users missing in demographics are kept
C1950 rows, because rows from both models are combined
D950 rows, because only users present in both models are kept
Attempts:
2 left
💡 Hint

Remember what an inner join does to rows when keys don't match.

🔧 Debug
advanced
2:00remaining
Identifying the Error in a dbt Model Reference

Look at this dbt model SQL snippet:

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

When running dbt, it fails with an error saying the referenced model does not exist. What is the most likely cause?

AThe model name in ref is misspelled or does not match any model file
BThe SQL syntax is invalid because of missing semicolon
CThe {{ ref() }} function cannot be used inside select statements
DThe model file is missing a schema declaration
Attempts:
2 left
💡 Hint

Check the spelling and existence of the referenced model.

🚀 Application
expert
3:00remaining
Choosing the Correct Layer for a New Data Transformation

You have raw sales data coming from multiple sources with inconsistent date formats and missing values. You want to create a model that standardizes dates and fills missing values before calculating monthly sales totals. According to the staging, intermediate, and marts pattern, where should you place the model that standardizes dates and fills missing values?

AIn the marts layer, because it creates final reports
BIn the staging layer, because it prepares raw data for further use
COutside dbt, because data cleaning should not be done in dbt
DIn the intermediate layer, because it aggregates data for analysis
Attempts:
2 left
💡 Hint

Think about where raw data is first cleaned and standardized.

Practice

(1/5)
1. What is the main purpose of the staging layer in the dbt pattern Staging, intermediate, and marts?
easy
A. To create final reports and dashboards
B. To aggregate data for business metrics
C. To clean and prepare raw data for further transformations
D. To store backup copies of raw data

Solution

  1. Step 1: Understand the role of staging

    The staging layer is where raw data is cleaned and standardized to make it ready for analysis.
  2. Step 2: Differentiate from other layers

    Intermediate and marts layers perform transformations and aggregations, while staging focuses on cleaning.
  3. Final Answer:

    To clean and prepare raw data for further transformations -> Option C
  4. Quick Check:

    Staging = cleaning raw data [OK]
Hint: Staging = clean raw data first [OK]
Common Mistakes:
  • Confusing staging with marts layer
  • Thinking staging creates final reports
  • Assuming staging stores backups
2. Which of the following is the correct way to reference a model in dbt within the intermediate layer?
easy
A. SELECT * FROM stg_customers
B. SELECT * FROM {{ ref('stg_customers') }}
C. SELECT * FROM ref('stg_customers')
D. SELECT * FROM {{ source('stg_customers') }}

Solution

  1. Step 1: Recall dbt model referencing syntax

    dbt uses the Jinja function ref() inside double curly braces to reference models.
  2. Step 2: Identify correct syntax

    The correct syntax is {{ ref('model_name') }}, so {{ ref('stg_customers') }} is correct.
  3. Final Answer:

    SELECT * FROM {{ ref('stg_customers') }} -> Option B
  4. Quick Check:

    Use {{ ref('model') }} to reference models [OK]
Hint: Use {{ ref('model_name') }} to reference models [OK]
Common Mistakes:
  • Omitting curly braces around ref()
  • Using source() instead of ref() for models
  • Calling ref() without curly braces
3. Given the following dbt model code in the intermediate layer:
SELECT
  customer_id,
  COUNT(order_id) AS total_orders
FROM {{ ref('stg_orders') }}
GROUP BY customer_id

What will be the output columns of this model?
medium
A. customer_id, total_orders
B. order_id, total_orders
C. customer_id, order_id
D. customer_id only

Solution

  1. Step 1: Analyze SELECT statement

    The query selects customer_id and counts order_id as total_orders.
  2. Step 2: Understand GROUP BY effect

    Grouping by customer_id means output will have one row per customer with total orders counted.
  3. Final Answer:

    customer_id, total_orders -> Option A
  4. Quick Check:

    Output columns = customer_id and total_orders [OK]
Hint: GROUP BY columns + aggregated columns appear in output [OK]
Common Mistakes:
  • Expecting order_id as output column
  • Missing aggregated column in output
  • Confusing GROUP BY with WHERE clause
4. You wrote this dbt model in the marts layer:
SELECT
  customer_id,
  SUM(total_orders) AS total_orders
FROM {{ ref('int_customer_orders') }}
GROUP BY customer_id

But the model fails with an error about total_orders. What is the likely cause?
medium
A. Missing GROUP BY clause
B. SUM() cannot be used in marts layer
C. Incorrect use of {{ ref() }} syntax
D. The referenced model int_customer_orders does not have a column named total_orders

Solution

  1. Step 1: Check referenced model columns

    The error suggests total_orders column is missing in int_customer_orders.
  2. Step 2: Validate aggregation usage

    SUM() is valid in marts layer and GROUP BY is present, so those are not issues.
  3. Final Answer:

    The referenced model int_customer_orders does not have a column named total_orders -> Option D
  4. Quick Check:

    Column missing in referenced model causes error [OK]
Hint: Check referenced model columns before aggregating [OK]
Common Mistakes:
  • Assuming SUM() is invalid in marts
  • Forgetting GROUP BY with aggregation
  • Misusing ref() syntax
5. You want to build a sales report in the marts layer that shows total sales per region. Your staging layer has raw sales data, and the intermediate layer calculates sales per store. Which is the best approach to build this report using the staging, intermediate, and marts pattern?
hard
A. Reference the intermediate sales per store model in the marts layer and aggregate sales by region
B. Directly query the raw sales data in the marts layer and group by region
C. Aggregate sales by region in the staging layer
D. Create the sales report in the intermediate layer without using marts

Solution

  1. Step 1: Follow pattern responsibilities

    Staging cleans raw data, intermediate transforms data per store, marts create final aggregates like sales per region.
  2. Step 2: Use intermediate model in marts

    Use the intermediate sales per store model as input to marts, then aggregate by region for the report.
  3. Final Answer:

    Reference the intermediate sales per store model in the marts layer and aggregate sales by region -> Option A
  4. Quick Check:

    Marts aggregate intermediate data for final reports [OK]
Hint: Build reports in marts using intermediate models [OK]
Common Mistakes:
  • Skipping intermediate layer aggregation
  • Aggregating raw data directly in marts
  • Doing final aggregation in staging
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard