Trigger actions when a data quality check fails¶
A violation action automatically responds when a data metric function (DMF) detects a data quality issue. The action runs as part of the DMF evaluation, so you don’t need a separate task that polls the results table before you can respond to an issue.
A data quality issue is detected when an expectation on the association is violated or anomaly detection flags a result.
Violation action types¶
The following action types are supported:
TYPE | TARGET | Behavior | For more information |
|---|---|---|---|
EXECUTE_TASK | A task | Runs the target task once, the same as EXECUTE TASK. | Run a task when a data quality check fails |
SKIP_DOWNSTREAM_DYNAMIC_TABLE_REFRESH | None | Skips refreshes of the dynamic tables that depend on the monitored object until the check passes. | Skip downstream dynamic table refreshes when a data quality check fails |
Use EXECUTE_TASK to respond to an issue programmatically; for example, to quarantine rows that fail a check, start a remediation
pipeline, or record the issue in an audit table. Use SKIP_DOWNSTREAM_DYNAMIC_TABLE_REFRESH to stop data that fails a check from
propagating through a dynamic table pipeline.
Set a violation action¶
A violation action is configured on the association between a table or view and a DMF, the same granularity as an expectation. Two associations on the same table carry independent actions.
To set an action, specify the ON_VIOLATION_ACTION property with a property block that identifies the action TYPE and, if the type
requires one, its TARGET. You can set the property on an existing association:
You can also set the property in the same statement that adds the DMF and its expectation:
An action fires only when the association detects a data quality issue. If the association has no expectation and doesn’t use anomaly detection, the action never fires.
Set multiple violation actions¶
To respond to an issue in more than one way, specify a parenthesized list of property blocks. For example, the following statement runs a task and also skips downstream dynamic table refreshes when the check fails:
An association can have up to eight violation actions. Each action must be unique: you can’t specify the same action type with the same
target twice, but you can specify the same type with different targets; for example, two EXECUTE_TASK actions that run different
tasks. When the association detects a data quality issue, every action runs.
For the privileges required by each action type, see Run a task when a data quality check fails and Skip downstream dynamic table refreshes when a data quality check fails.
Replace or remove a violation action¶
To replace the actions on an association, set a new ON_VIOLATION_ACTION. The new value replaces all of the existing actions; to
keep an existing action, include it in the new value:
To remove all of the actions, set the property to an empty property block. The DMF and its expectations remain in place:
Check the status of a violation action¶
The DATA_METRIC_FUNCTION_REFERENCES function returns a VIOLATION_ACTION column for each association.
The column contains a JSON array with one element for each action configured on the association, in the order that you specified them.
Each element describes the action and the outcome of the most recent evaluation that observed it. The column is NULL when no action is
configured.
For example, an association with a task action and a dynamic table action returns a value like the following:
To return one row for each action, use FLATTEN:
Each element of the array contains the following fields:
| Field | Description |
|---|---|
type | The action type, such as EXECUTE_TASK or SKIP_DOWNSTREAM_DYNAMIC_TABLE_REFRESH. |
target | The fully qualified name of the target object. Omitted when the action type takes no target, or when the target no longer exists. |
last_trigger_status | The outcome of the most recent evaluation that observed the action. Omitted until the first evaluation. |
The last_trigger_status field takes one of the following values:
| Status | Action types | Meaning |
|---|---|---|
NOT_TRIGGERED | All | The most recent evaluation detected no data quality issue. This is the expected value for healthy data. |
SCHEDULED | EXECUTE_TASK | A data quality issue was detected and the task run was scheduled. The run is visible in TASK_HISTORY. |
SKIPPED_TASK_DROPPED | EXECUTE_TASK | A data quality issue was detected, but the target task no longer exists, so no run was scheduled. |
FAILED_INSUFFICIENT_PRIVILEGE | EXECUTE_TASK | A data quality issue was detected, but the role that the DMF runs as can’t run the target task. |
FAILED | EXECUTE_TASK | A data quality issue was detected, but scheduling the task run failed for another reason. |
DOWNSTREAM_DYNAMIC_TABLE_REFRESH_SKIPPED | SKIP_DOWNSTREAM_DYNAMIC_TABLE_REFRESH | The most recent evaluation detected a data quality issue, so downstream dynamic table refreshes are skipped. |
The status reflects only the most recent evaluation and is overwritten by each evaluation. It isn’t a history of past actions. To see the outcome of each action, use TASK_HISTORY for a task, or dynamic table refresh history for skipped refreshes.
Limitations and considerations¶
- Each DMF association supports up to eight violation actions.
- Every action on an association runs when any expectation on the association is violated. You can’t route different expectations to different actions.
- A failure to run an action doesn’t fail the DMF evaluation. The failure is recorded in that action’s
last_trigger_status. - When you clone a table or view, its violation actions are copied to the clone.
- When a database or replication group is replicated, its violation actions are replicated. An
EXECUTE_TASKaction on the secondary runs the replicated copy of the target task. If the target task isn’t replicated, the action’stargetfield is omitted on the secondary. Thelast_trigger_statusfield isn’t replicated; it reflects evaluations on the secondary only.