dbt Analytics Engineering (50 Qs)•Part 2: Advanced Modeling, Incremental Builds & Macros (Mid-Level)
How do you create Custom Generic Test Macros?
junior LevelCode ExampleTypeScript
In Simple Words:
Create a macro in macros/ with the prefix test_. The test must return failing rows:
sql
-- macros/test_is_even.sql
{% test is_even(model, column_name) %}
SELECT {{ column_name }}
FROM {{ model }}
WHERE ({{ column_name }} % 2) != 0
{% endtest %}
Use it in YAML:
yaml
columns:
- name: batch_quantity
tests:
- is_even