0
0
dbtdata~5 mins

Calling macros across projects in dbt - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a macro in dbt?
A macro in dbt is a reusable piece of code written in Jinja that helps automate repetitive tasks in your data transformations.
Click to reveal answer
beginner
How do you call a macro from another project in dbt?
You call a macro from another project by prefixing the macro name with the project name and a dot, like this: {{ project_name.macro_name() }}.
Click to reveal answer
intermediate
Why would you want to call macros across projects in dbt?
Calling macros across projects helps you reuse common logic and avoid duplication, making your code cleaner and easier to maintain.
Click to reveal answer
intermediate
What must be configured to enable calling macros across projects in dbt?
You must list the other project as a dependency in your packages.yml file and run dbt deps to install it.
Click to reveal answer
beginner
Example: How to call a macro named calculate_metrics from a project named analytics_utils?
Use {{ analytics_utils.calculate_metrics() }} inside your dbt model or macro to call it from the analytics_utils project.
Click to reveal answer
How do you reference a macro from another dbt project?
AUse <code>{{ macro_name() }}</code> without prefix
BUse <code>{{ project_name.macro_name() }}</code>
CImport the macro with Python import
DMacros cannot be called across projects
What file do you update to add a dependency on another dbt project?
Apackages.yml
Bdbt_project.yml
Cprofiles.yml
Dmacros.yml
What command installs dependencies listed in packages.yml?
Adbt deps
Bdbt run
Cdbt install
Ddbt build
Why is calling macros across projects useful?
ATo slow down builds
BTo duplicate code
CTo reuse common logic
DTo avoid using macros
Which syntax is correct to call macro foo from project bar?
A{{ foo.bar() }}
B{{ foo() }}
C{{ bar::foo() }}
D{{ bar.foo() }}
Explain how to set up and call a macro from another dbt project.
Think about configuration and syntax steps.
You got /3 concepts.
    Why is it beneficial to call macros across projects in dbt?
    Consider how sharing code helps in teamwork.
    You got /3 concepts.