Understand and Use dbt Jinja Macros

Lab Steps

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

The hands-on lab is part of this learning path

Ready for the real environment experience?

DifficultyIntermediate
Time Limit1h
Students30
Ratings
5/5
starstarstarstarstar

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:

About the Author
Students28620
Labs106
Courses2
Learning paths8

Stefano studies Computer Science and is passionate about technology. He loves working with Cloud services and learning all the best practices for them. Google Cloud Platform and Amazon Web Services are the cloud providers he prefers. He is a Google Cloud Certified Associate Cloud Engineer. Node.js is the programming language he always uses to code. When he's not involved in studying or working, Stefano loves riding his motorbike and exploring new places.