Using Macros from a Package
Explore how to integrate macros from external dbt packages by configuring the macro-paths list and learn to override package macros using dispatch settings. This lesson guides you through managing macro conflicts and customizing behavior for specific adapters, improving your project's modularity and flexibility.
We'll cover the following...
Adding a package to the macro-paths list
After running dbt deps, we might need to use the log_info macro from the dbt-utils package. This macro allows us to log a formatted message to the command line. If we try to call that macro directly, like this:
We get a compilation error:
Compilation Error in model other (models/other.sql) 'log_info' is undefined.This can happen when calling a macro that does not exist.Check for typos and/or install package dependencies with "dbt deps".
This is because dbt does not know it can look for macros in that package.
To change that, we need to edit the macro-paths list in the dbt_project.yml file, and add the path to the macros folder in the dbt-utils package.
This time, our log works: ...
16:28:05 2 of 2 START sql view model educative.other .............................. [RUN]16:28:05 16:28:05 + This is just a dummy model16:28:06 2 of 2 OK created sql view model educative.other .............................. [CREATE VIEW (0 processed) in 0.91s]