Challenge - 5 Problems
Cross-Project Macro Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2: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_priceAttempts:
2 left
💡 Hint
Remember that macros from other projects can be called using the project name as a prefix.
✗ Incorrect
The macro
calculate_discount multiplies the input price by 0.9, so calling it with 100 returns 90.0.🧠 Conceptual
intermediate1: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?
Attempts:
2 left
💡 Hint
Think about how dbt avoids macro name collisions.
✗ Incorrect
dbt requires using the project name prefix when calling macros from other projects to avoid naming conflicts.
🔧 Debug
advanced2: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?Attempts:
2 left
💡 Hint
Check if the other project is properly included as a dependency.
✗ Incorrect
If
project_x is not added as a dependency in project_y, dbt cannot find its macros, causing the error.❓ data_output
advanced2: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() }}Attempts:
2 left
💡 Hint
Macros return raw SQL snippets to be inserted as-is.
✗ Incorrect
The macro returns the condition
status = 'active' without quotes or extra keywords, so it fits correctly in the WHERE clause.🚀 Application
expert3: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'?Attempts:
2 left
💡 Hint
Remember to use the project prefix and pass variables correctly.
✗ Incorrect
To call a macro from another project, use the project prefix and pass the variable without quotes.