0
0
dbtdata~20 mins

Calling macros across projects in dbt - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Cross-Project Macro Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of calling a macro from another project
Given two dbt projects, project_a and project_b, where project_b defines a macro calculate_discount() that returns price * 0.9. In project_a, you call this macro using {{ project_b.calculate_discount(100) }}. What is the output?
dbt
{% macro calculate_discount(price) %}{{ price * 0.9 }}{% endmacro %}

-- In project_a model:
select {{ project_b.calculate_discount(100) }} as discounted_price
A100
B90.0
CSyntaxError: macro not found
D10.0
Attempts:
2 left
💡 Hint
Remember that macros from other projects can be called using the project name as a prefix.
🧠 Conceptual
intermediate
1:30remaining
Understanding macro namespace in dbt projects
In dbt, when calling a macro from another project, which of the following is true about the macro namespace?
AMacros must be called with the project name prefix to avoid conflicts.
BMacros from other projects are automatically imported without prefix.
CMacros cannot be called across projects in dbt.
DMacros from other projects override local macros without prefix.
Attempts:
2 left
💡 Hint
Think about how dbt avoids macro name collisions.
🔧 Debug
advanced
2:30remaining
Debugging macro call error across projects
You have a macro format_date() defined in project_x. When calling {{ project_x.format_date('2024-01-01') }} in project_y, you get an error: Runtime Error: 'project_x' is undefined. What is the most likely cause?
AMacros cannot accept string arguments across projects.
BThe macro name <code>format_date</code> is misspelled in <code>project_x</code>.
CThe <code>project_x</code> is not listed as a dependency in <code>project_y</code>'s <code>packages.yml</code>.
DThe macro must be called without the project prefix.
Attempts:
2 left
💡 Hint
Check if the other project is properly included as a dependency.
data_output
advanced
2:00remaining
Result of macro generating SQL across projects
In project_main, you call a macro from project_utils that generates a SQL snippet to filter rows where status = 'active'. The macro is called as {{ project_utils.filter_active() }} inside a model's where clause. What is the resulting SQL snippet inserted?
dbt
{% macro filter_active() %}status = 'active'{% endmacro %}

-- Usage in project_main model:
select * from users where {{ project_utils.filter_active() }}
A'status = active'
BWHERE status = 'active'
Cstatus == 'active'
Dstatus = 'active'
Attempts:
2 left
💡 Hint
Macros return raw SQL snippets to be inserted as-is.
🚀 Application
expert
3:00remaining
Using macros across projects to standardize date formatting
You want to standardize date formatting across multiple dbt projects by defining a macro format_date(date, format) in project_common. How should you call this macro in project_sales to format the date order_date as 'YYYY-MM-DD'?
A{{ project_common.format_date(order_date, 'YYYY-MM-DD') }}
B{{ format_date(order_date, 'YYYY-MM-DD') }}
C{{ project_sales.format_date(order_date, 'YYYY-MM-DD') }}
D{{ project_common.format_date('order_date', 'YYYY-MM-DD') }}
Attempts:
2 left
💡 Hint
Remember to use the project prefix and pass variables correctly.