Skip to main content

Macro

SQL

The Macro gem lets you use a macro that you have defined or imported in your SQL project. Macros provide a simple interface where you can define the values of your macro parameters (arguments). Use the Macro gem when you:

  • Import macros via DBT Hub dependency.
  • Want to use a simple interface for custom gems.

Parameters

ParameterDescription
MacroThe macro that you wish to use.
Note: You can only select a Gem macro. You cannot select a macro defined as a function.
Parameter 1A parameter that is defined in the macro. This is a value that is passed to the macro.
Parameter NAdditional parameters that are defined in the macro.

Example: dbt_utils

For this example, assume you want to use the dbt_utils package as a dependency in your project.

  1. Open the Options (ellipses) menu in the project header.
  2. Select Dependencies.
  3. Click + Add Dependency.
  4. Choose the dependency type (Project, GitHub, or DBT Hub).
  5. Add the package dbt-labs/dbt_utils.
  6. Choose version 1.3.0.
  7. Click Create.
  8. Click Reload and Save to download the package.
  9. Review the functions and gems that are available in the dbt_utils package. You can click any function or gem to see the underlying macro code.

To use one of the imported gems in your pipeline:

  1. Add the Macro gem to the canvas.
  2. Open the gem configuration.
  3. In the Macro field, choose the gem that you want to use. The gem parameters should appear.
  4. Fill in the parameters. These are the arguments of the dbt macro.
  5. Save and run the gem.

The following image shows the unpivot macro imported from dbt_utils in a Macro gem.

Unpivot macro