- Categories:
System functions (System Information)
SYSTEM$PREDECESSORS_ STATE¶
Indicates whether the predecessors of the current task completed in the states described by a specified condition. Use this function in the
WHEN clause of a task in a task graph to run the task on outcomes other than “all predecessors succeeded.”
For an explanation of how this function changes the way Snowflake schedules tasks in a graph, see How advanced branching changes scheduling.
Syntax¶
Arguments¶
'condition'The condition to evaluate against the completion states of the current task’s predecessors. Specify one of the following values:
Condition Returns TRUE when ALL_SUCCEEDEDEvery predecessor succeeded. This is the default condition that Snowflake applies to a task that doesn’t specify a predecessor condition. ALL_FAILEDEvery predecessor failed. ALL_DONEEvery predecessor reached a terminal state, in any combination of SUCCEEDED,FAILED,SKIPPED, andCANCELLED.ALL_SKIPPEDEvery predecessor was skipped. AT_LEAST_ONE_FAILEDOne or more predecessors failed. AT_LEAST_ONE_SUCCEEDEDOne or more predecessors succeeded. NONE_FAILEDNo predecessor failed. Every predecessor either succeeded or was skipped. NONE_FAILED_MIN_ONE_SUCCEEDEDNo predecessor failed, and at least one predecessor succeeded. NONE_SKIPPEDNo predecessor was skipped. Every predecessor either succeeded or failed. The condition name must be enclosed in single quotes.
Returns¶
Returns TRUE if the completion states of the current task’s predecessors satisfy the specified condition, and FALSE otherwise.
Usage notes¶
- You can only call this function from a
WHENclause on a child task. Calling it from a root task, a finalizer task, or outside of a task fails when you resume the task or commit the task definition. - Every condition is evaluated after all of the current task’s predecessors reach a terminal state. A task is scheduled once its
predecessors are done, not as soon as the condition could first be satisfied. For example, a task using
AT_LEAST_ONE_FAILEDdoesn’t run the moment the first predecessor fails. Snowflake waits for the remaining predecessors to finish, and then the condition returnsTRUEbecause at least one of them failed. - The function evaluates the predecessors of the current task only. It doesn’t consider tasks elsewhere in the graph. To check the state of a specific named task, use SYSTEM$TASK_COMPLETION_STATE.
- A task can combine this function with other supported
WHENexpressions, including SYSTEM$STREAM_HAS_DATA and SYSTEM$GET_PREDECESSOR_RETURN_VALUE. Snowflake evaluates the whole expression, so the task runs only when the combined expression isTRUE. - When a task graph contains at least one task that calls this function or
SYSTEM$TASK_COMPLETION_STATE, Snowflake schedules every task in the graph, no matter what state the
predecessors of each task completed in. Tasks in the graph that don’t specify a predecessor condition behave as though their
WHENclause ends withAND SYSTEM$PREDECESSORS_STATE('ALL_SUCCEEDED'). For the full description of this behavior, see How advanced branching changes scheduling.
Examples¶
Run a cleanup task only when every predecessor failed:
Create the same root and child task using the Python API, setting
the child task’s predecessors and condition properties directly:
Run a reporting task after every predecessor reaches a terminal state, whatever that state is:
Run a task when no predecessor failed and at least one produced data, and only when a stream also has data to process: