hands-on lab

Understand and Use dbt Jinja Macros

Difficulty: Intermediate
Duration: Up to 1 hour
Students: 160
Rating: 5/5
Get guided in a real environmentPractice with a step-by-step scenario in a real, provisioned environment.
Learn and validateUse validations to check your solutions every step of the way.
See resultsTrack your knowledge and monitor your progress.

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:

Covered topics

Lab steps

Understanding What Are dbt Jinja Macros
Connecting to the dbt Web IDE
Defining a Custom dbt Macro
Creating a Model Leveraging dbt Macros
Executing the dbt Model