Macros
An Ascend Macro is a reusable SQL logic block that lets you implement functionality once and use it across multiple Components. Macros use Jinja2 template syntax and are defined in .sql files within a macros/ directory in your Project root.
Why use Macros
- Consistency: Apply the same logic across Components without copy-pasting
- Maintainability: Update logic in one place, changes propagate everywhere
- Readability: Abstract complex SQL into named, parameterized functions
How Macros work
Define a macro once:
macros/utils.sql
{% macro standardize(col_name) %}
LOWER(TRIM({{ col_name }}))
{% endmacro %}
Import and use it in any SQL Transform:
{% from 'macros/utils.sql' import standardize %}
SELECT
id,
{{ standardize('name') }} AS clean_name
FROM {{ ref('my_table') }}
Next steps
- Build SQL Macros - Step-by-step guide