0
0
dbtdata~30 mins

Built-in Jinja context variables in dbt - Mini Project: Build & Apply

Choose your learning style9 modes available
Exploring Built-in Jinja Context Variables in dbt
📖 Scenario: You are working on a dbt project to build data models. You want to understand how to use built-in Jinja context variables to make your models dynamic and informative.
🎯 Goal: Learn to access and display built-in Jinja context variables in dbt models to understand the current model's metadata.
📋 What You'll Learn
Create a variable to hold the model name using the built-in Jinja variable
Create a variable to hold the model's unique identifier using the built-in Jinja variable
Use a Jinja for loop to list all columns available in the model using the built-in context variable
Print the model name, unique identifier, and list of columns
💡 Why This Matters
🌍 Real World
In real dbt projects, these built-in variables help you write dynamic models that adapt to different environments and provide metadata for debugging.
💼 Career
Understanding Jinja context variables is essential for dbt developers and data engineers to build maintainable and flexible data transformation pipelines.
Progress0 / 4 steps
1
Create a variable for the model name
Create a variable called model_name and set it to the built-in Jinja context variable this.name which holds the current model's name.
dbt
Need a hint?

The variable this gives info about the current model. Use this.name to get the model's name.

2
Create a variable for the model's unique identifier
Create a variable called model_id and set it to the built-in Jinja context variable this.identifier which holds the unique identifier of the current model.
dbt
Need a hint?

Use this.identifier to get the unique id of the model.

3
List all columns in the model
Create a variable called column_names that uses a Jinja for loop over columns to collect all column names into a list.
dbt
Need a hint?

The columns variable holds all columns. Use a for loop to get each col.name.

4
Print the model info and columns
Print the model_name, model_id, and the list column_names using Jinja's print or log statements.
dbt
Need a hint?

Use {{ variable }} to display variables in Jinja templates.