0
0
dbtdata~20 mins

ref() function for model dependencies in dbt - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
dbt ref() Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of ref() in a dbt model SQL
Given the following dbt model SQL code, what will be the fully qualified table name generated by the ref('customers') function if the project is deployed in the analytics schema of the prod database?
dbt
select * from {{ ref('customers') }}
A"prod"."analytics"."customers"
B"analytics"."prod"."customers"
C"prod"."customers"."analytics"
D"customers"."analytics"."prod"
Attempts:
2 left
💡 Hint
Remember that ref() resolves to the database, schema, and table name in that order.
data_output
intermediate
1:30remaining
Number of rows returned using ref() in a join
Consider two dbt models: orders and customers. Consider the following model SQL:
select o.order_id, c.customer_name
from {{ ref('orders') }} o
join {{ ref('customers') }} c on o.customer_id = c.customer_id

If orders has 100 rows and customers has 10 rows, and every order has a matching customer, how many rows will this query return?
A110
B10
C1000
D100
Attempts:
2 left
💡 Hint
Think about how a join works when every order has a matching customer.
🔧 Debug
advanced
1:30remaining
Identify the error caused by incorrect use of ref()
What error will occur when running this dbt model SQL?
select * from {{ ref(customers) }}

Note: customers is not in quotes.
ARuntime error: table not found
BCompilation error: 'customers' is not defined
CSyntax error: missing quotes around string
DNo error, runs successfully
Attempts:
2 left
💡 Hint
Look at how the argument to ref() is passed.
🧠 Conceptual
advanced
2:00remaining
Understanding model dependency graph with ref()
In dbt, if model A uses {{ ref('B') }} and model B uses {{ ref('C') }}, which models will be built before A?
AOnly model <code>B</code> will be built before <code>A</code>
BOnly model <code>C</code> will be built before <code>A</code>
CModels <code>B</code> and <code>C</code> will be built before <code>A</code>
DModels <code>A</code>, <code>B</code>, and <code>C</code> are built simultaneously
Attempts:
2 left
💡 Hint
Think about how dependencies chain in dbt models.
🚀 Application
expert
2:30remaining
Predict the effect of changing ref() argument on model build order
You have three models: sales, customers, and regions. The sales model uses {{ ref('customers') }}. You change the sales model to use {{ ref('regions') }} instead. What is the impact on the build order?
AThe <code>sales</code> model will now build after <code>regions</code> instead of <code>customers</code>
BThe build order remains the same; <code>sales</code> builds after both <code>customers</code> and <code>regions</code>
CThe <code>sales</code> model will build before both <code>customers</code> and <code>regions</code>
DThe <code>sales</code> model will build independently without waiting for any other model
Attempts:
2 left
💡 Hint
Consider how changing the ref() target changes dependencies.