Skip downstream dynamic table refreshes when a data quality check fails¶
To stop data that fails a quality check from propagating through a dynamic table pipeline, configure a
SKIP_DOWNSTREAM_DYNAMIC_TABLE_REFRESH violation action on the check. When the check detects a
data quality issue, Snowflake skips the affected refreshes and preserves the downstream dynamic tables’ existing contents. After you
correct the data and the check passes, refreshes proceed automatically.
A check configured this way is a data quality gate. For example, a revenue pipeline can refresh successfully even when incoming orders have missing prices: the SQL completes, but the resulting revenue totals are incomplete. A gate keeps the previous results in place instead of publishing an update that fails your quality requirements.
Use a gate on a base table to check incoming data, or on an intermediate dynamic table to validate its results before downstream dynamic tables consume them. You configure the gate once on the monitored object; downstream dynamic tables don’t need to opt in.
What a gate protects¶
A gate controls refreshes downstream of the object that carries the quality check. It doesn’t reject writes, roll back a refresh, or quarantine data on that object.
For example:
If the check on dt_orders_enriched fails, the refreshed contents of dt_orders_enriched remain committed and queryable. The gate
skips refreshes of dt_orders_daily; it doesn’t undo the refresh of dt_orders_enriched.
Downstream dynamic tables retain their previous contents, which aren’t guaranteed to be clean. Those contents can become stale while the issue persists.
A skipped refresh doesn’t suspend the dynamic table. Its scheduling state stays the same, and Snowflake continues to attempt refreshes on schedule.
Configure a data quality gate¶
To configure a gate, set the SKIP_DOWNSTREAM_DYNAMIC_TABLE_REFRESH violation action on the association between a data metric function
(DMF) and a table or dynamic table. The action applies when an expectation on that association
is violated or anomaly detection flags a result.
You need the privileges required to modify the DMF association and its expectations. For more information, see Access control for data quality. No privileges on the downstream dynamic tables are required. Because the gate affects dependent dynamic tables regardless of who owns them, coordinate your quality requirements with the owners of downstream dynamic tables.
For this action, the DMF schedule must be TRIGGER_ON_CHANGES. Snowflake rejects SKIP_DOWNSTREAM_DYNAMIC_TABLE_REFRESH on a table or view whose effective schedule is time-based,
either a cron expression or a fixed interval. A table without its own schedule inherits the schedule of its schema or account, and the
account default is 60 MINUTES, so set TRIGGER_ON_CHANGES on the table before you add the action:
A time-based schedule can leave the saved measurement out of date relative to downstream refreshes, so the action requires
TRIGGER_ON_CHANGES.
For an existing DMF association with an expectation, set the violation action:
The action takes no TARGET. It applies to all dynamic tables that depend on the monitored object, directly or indirectly.
After you set this action, you can’t change the schedule of the monitored object to a time-based value. Snowflake rejects SET or UNSET
of DATA_METRIC_SCHEDULE that would make the effective schedule a cron expression or interval. To use a time-based schedule, remove the
violation action first.
For information about replacing or removing the action, see Replace or remove a violation action.
Measurement freshness and recovery¶
Before a downstream dynamic table refreshes, Snowflake checks the applicable upstream gates. A violated gate causes Snowflake to skip that refresh attempt.
The DMF schedule determines how current the measurement must be:
TRIGGER_ON_CHANGESrequires an up-to-date measurement. If the available measurement isn’t current, Snowflake submits a new evaluation and waits for it, up to a limited amount of time.- A scheduled interval uses the latest stored measurement without waiting for a new one. That measurement can be older than the data being refreshed.
Use TRIGGER_ON_CHANGES when your check must be current with each refresh. A check on a scheduled interval provides best-effort gating
and leaves a window in which newer data hasn’t been evaluated.
If an evaluation fails or doesn’t finish in time, Snowflake skips the affected refresh attempt. Investigate the evaluation problem before you expect refreshes to recover.
The gate automates the recovery of refreshes, not the repair of data. You must correct the underlying issue. After the applicable checks pass, downstream refreshes proceed at the next refresh opportunity. No manual resume is required.
Identify skipped refreshes¶
To check whether a gate is currently skipping refreshes, query the VIOLATION_ACTION column of the DMF association. A
last_trigger_status of DOWNSTREAM_DYNAMIC_TABLE_REFRESH_SKIPPED means that the most recent evaluation detected an issue. For more
information, see Check the status of a violation action.
The association status isn’t a record of each downstream refresh. To identify individual skipped refreshes, query the refresh history of the downstream dynamic table:
The refresh history distinguishes a refresh that the gate skipped directly from a skip that cascaded from an upstream dynamic table:
| Relationship to the monitored object | STATE | STATE_CODE |
|---|---|---|
| Directly downstream | UPSTREAM_DATA_QUALITY_VIOLATION | UPSTREAM_DATA_QUALITY_VIOLATION |
| Further downstream, affected by a cascaded skip | SKIPPED | UPSTREAM_SKIP |
For a refresh that the gate skipped directly, STATE_MESSAGE identifies the upstream object and the DMF that detected the issue.
The dataQualityGateTimeMs field in the STATISTICS column of the refresh history reports how long the gate held the refresh while it
waited for a data quality result. For a skipped refresh, it’s the only field in STATISTICS.
Example: Prevent missing prices from reaching a revenue report¶
The following pipeline calculates order line totals and then aggregates them into daily revenue:
A missing unit_price value produces a NULL line total, which SUM ignores. To prevent that incomplete order from propagating downstream,
the example configures a gate that requires every order to have a price.
The example assumes that the transform_wh warehouse exists and that you have the required privileges.
Warning
Use a test schema, because the example replaces any existing objects that have the same names.
Create the pipeline and quality check¶
The example sets the DMF schedule to TRIGGER_ON_CHANGES, so the gate requires an up-to-date measurement before it allows downstream
refreshes:
The expectation VALUE = 0 requires the null count for unit_price to be zero. Its violation action gates both downstream dynamic
tables.
Introduce a missing price¶
After the initial refreshes complete, insert an order that has a NULL price:
The check fails. Snowflake skips the next affected refresh of dt_orders_enriched, and the skip cascades to dt_orders_daily. The
invalid order remains queryable in raw_orders.
Inspect the skipped refreshes¶
After the next scheduled refresh attempt, inspect the latest refresh of both downstream dynamic tables:
The dt_orders_enriched row shows the UPSTREAM_DATA_QUALITY_VIOLATION state code for the refresh that the gate skipped directly.
The dt_orders_daily row shows the UPSTREAM_SKIP state code for the cascaded skip.
Correct the price¶
Update the order with its price:
After a new measurement passes, Snowflake lets downstream refreshes proceed at the next refresh opportunity. After both dynamic tables
refresh, the order contributes 59.98 to daily revenue.
Limitations and considerations¶
- Downstream dynamic tables can exceed their target lag while refreshes are skipped. They catch up after refreshes resume.
- A skipped refresh isn’t a refresh failure. A manual refresh can complete without an error even when the gate causes it to skip. Inspect the refresh history to confirm the outcome.
- You can’t restrict the action to a subset of the downstream dynamic tables.
- This action isn’t supported on Cortex agents or on tables that are shared with you. Those objects can’t use
TRIGGER_ON_CHANGES. ALTER ACCOUNT SET DATA_METRIC_SCHEDULEdoesn’t check the tables and agents already in the account. LaterSETorUNSETstatements on a table or schema are still checked while this action is attached. The schedule restriction doesn’t apply toEXECUTE_TASKactions.- A row access policy or masking policy can hide rows from the check. A data metric association is evaluated as the table owner’s role, or
as the role set by
EXECUTE AS ROLE. Policies apply to the role that runs the evaluation, so that role can miss rows that the table owner can see. The check can pass while the downstream dynamic table refreshes from those rows. The dynamic table refresh runs as the table’s owner or the delegated role, not as the dynamic table’s owner. This is expected: the table owner decides what the gate checks. - A check that reads a second table runs again only when the measured table changes. For example,
REFERENTIAL_INTEGRITY_COUNTcompares the measured table with a reference table. A change to the reference table alone doesn’t trigger a new check, so rows that previously passed can become invalid while the downstream dynamic table still refreshes. - If you replace a gated base table with CREATE OR REPLACE, the gate applies the data quality checks on the replacement table. Because the replacement table doesn’t keep the original table’s DMF associations, add the DMF, its expectations, and the violation action to the replacement table to keep gating the downstream dynamic tables.
For limitations that apply to all violation actions, see Limitations and considerations.
Next steps¶
For more information about interpreting refresh history, see Monitor dynamic tables.