Keeping consistency by reusing code – macros
In the previous chapters, we used dbt to chain simple SQL-based transformations to produce refined information for our reports. That works fine and offers a good way of working with SQL code, but it would not be a momentous improvement over the previous tools available for the job.
One main difference that sets dbt apart from other tools in transforming data lies in its ability to easily define macros, which are very similar to functions in programing languages and allow us to reuse logic and pieces of SQL code to produce the final SQL code to be executed in the database.
The other huge difference is the simplicity of incorporating testing while writing code and running the tests along with the code to keep data quality in check, as we will see later in the next chapter.
You write dbt macros in a scripting language called Jinja, which is based on Python and used in many other Python-based projects.
Using macros, you can...