Understand and Use dbt Jinja Macros
Description
dbt is a powerful tool to leverage existing data, model and transform it, and finally materialize it in order to let business stakeholders access the data. dbt is also an easy-to-use and rich-in features tool. Macros are one of them.
Macros are functions written in Jinja, a great templating language, that enables you to use programming structures like if/else and loops, define logic, and change the way your project builds depending on conditions. You can also access environment variables. They are mainly used to represent and materialize a logic you want to implement in your dbt transformations.
By using dbt, you can use some native macros such as ref and source, but you can also define custom ones. dbt also offers you the possibility to implement Jinja code directly into your dbt models, without the need of defining a macro.
In this lab, you will understand what are macros, you will use native dbt macros, and you will define a custom macro.
Learning Objectives
Upon completion of this lab, you will be able to:
- Understand what are Jinja macros and how to use them
- Create custom Jinja macros
Intended Audience
- Data engineers who need to use dbt macros
- Developers who need to develop reusable logics in dbt
Prerequisites
To get the most from this lab, you should have basic knowledge of dbt. To get ready, you can use the following labs: