Use the Coalesce Test Stage Macro
Coalesce provides built-in data validation tests that can be configured via the Testing UI and metadata. However, sometimes more custom or complex tests are needed.
By leveraging the test_stage()
built-in macro and SQL templates, you can create user-defined test nodes to validate data flows.
Test Stage Limitations
The out-of-the-box testing functionality has some limitations:
- Manual configuration of test logic required
- Hard to reuse tests across nodes
- Limited flexibility in SQL and controls
Creating Your Test
You'll need to:
- Author a macro with your test logic and name it
test_<stg_name>
. In the examples we useMy Custom Test
. - Invoke the Macro within a custom node’s
Run Template
. - Control failure handling behavior with a true/false clause in the stage initiation.
This tests for NULLs and does not continue the test on a failure and will fail the node execution. Using false is what will cause the failure.
{{ test_stage('My Custom Test', false) }}
SELECT 1
FROM {{this}}
WHERE Col IS NULL
If you set the conditional to true
, the test will continue the node execution after the test failure.
{{ test_stage('My Custom Test', true) }}
SELECT 1
FROM {{this}}
WHERE Col IS NULL