How to Use Jinja w/ dbt Macros (3 Examples)

Опубликовано: 02 Октябрь 2024
на канале: Kahan Data Solutions
2,681
74

Get my Modern Data Essentials training (for free) & start building more reliable data architectures
https://www.ModernDataCommunity.com

-----

If you're using dbt, at some point you'll need to create a Macro.

If you're not familiar with Macros, essentially they are like "functions" in other programming languages.

They're used to create re-usable bits of code and make your project much more dynamic.

It's truly one of the most valuable parts of using dbt.


But the deeper you get into macros, the more you'll also run into Jinja.

And while powerful, Jinja itself has a bit of a learning curve.

In short, Jinja is a templating language that allows you to compile more complex queries.

Think of it like templating a website with reusable components (header, body, footer).

But instead of website parts, we're able to template SQL queries.


Like many things, this can get really complicated.

But if you know how to use a few key functions of Jinja, you'll be able to cover a wide variety of scenarios.


So with that said, in this video I want to walk you through 3 examples of how to use helpful Jinja functions within a custom dbt macro.

Whether you're brand new to Jinja or need a quick refresher, this will be a great working-session style video for you to check out.

Enjoy!

Timestamps:
0:00 - Intro
1:02 - Using SET Variables
4:40 - Running Queries
7:54- Using IF Conditions


Title & Tags:
How to Use Jinja w/ dbt Macros (3 Examples)
#kahandatasolutions #dataengineering #dbtdata