Task graphs: dependencies, roots and finalizers
A task graph orders related work. A child runs after its predecessors; a finalizer handles end-of-run actions without pretending a failed business step succeeded.
Understand the idea
This example uses the established root-task graph model with AFTER and FINALIZE. Newer task-graph objects have different configuration placement; do not mix the two models. Check account support for the documented syntax before running templates.
| Concept | What it means |
|---|---|
| Root | Defines the graph entry point and scheduling policy. |
| AFTER | Declares task dependencies. |
| Finalizer | Runs according to graph completion semantics, including relevant failure paths. |
| NO_OVERLAP | Prevents overlapping graph runs for this serialized design. |
A concrete example
All tasks start suspended. The observation label records predecessor success, while the finalizer deliberately does not claim successful business processing.
Remember: A dependency graph orders work; it does not make the entire graph one database transaction.
Explain it step by step · full theory
Understand the concept
This example uses the established root-task graph model with AFTER and FINALIZE. Newer task-graph objects have different configuration placement; do not mix the two models. Check account support for the documented syntax before running templates.
The root calls APPLY_EVENTS; a child records an observation; the finalizer records that the graph ended. These tasks do not share one transaction. If the root committed and the child failed, the root’s target changes remain committed.
Walk through the behavior
A finalizer is not proof of business success and cannot roll back a previous task’s committed transaction. It may not run when the root is skipped, such as a false WHEN condition. Give logs honest labels.
All tasks in this graph use the same owner role and schema. Suspend PROCESS_EVENTS and confirm no run remains before exercising the graph. Resume children and finalizer, then execute the root manually; leave the root suspended to avoid ongoing polling.
Words used in this lesson
- Root
- Defines the graph entry point and scheduling policy.
- AFTER
- Declares task dependencies.
- Finalizer
- Runs according to graph completion semantics, including relevant failure paths.
- NO_OVERLAP
- Prevents overlapping graph runs for this serialized design.
See how it works
Choose a step to explore the idea at your own pace.
Open the interactive explanation
Task graphs: dependencies, roots and finalizers
Start with the source
A task graph orders related work. A child runs after its predecessors; a finalizer handles end-of-run actions without pretending a failed business step succeeded.
Automatic playback is off for reduced motion. Select any step or use Previous and Next. Illustrations explain behavior; they are not live measurements.
Read the complete diagram explanation
- Start with the source
A task graph orders related work. A child runs after its predecessors; a finalizer handles end-of-run actions without pretending a failed business step succeeded.
- Follow the work
This example uses the established root-task graph model with AFTER and FINALIZE. Newer task-graph objects have different configuration placement; do not mix the two models. Check account support for the documented syntax before running templates.
- Explain the outcome
A dependency graph orders work; it does not make the entire graph one database transaction.
Try the SQL or command
Read → predict → run in your learning environment → compare. You can also learn by reading without an account.
New to SQL? Where to run it and how to read it
A query is a question written in SQL. Snowflake runs it and returns a result table. This website shows examples; it does not connect to your account.
- No account yet? Read and predict the output first. Follow the account and Snowsight lesson when you are ready.
- For SQL practice, use a learning account in Snowsight and select an authorized role and warehouse. A role determines permissions; a warehouse supplies processing power. Follow the example’s database/schema setup when it refers to stored objects.
- Read the entire example, including comments beginning with
--. Run the selected statement or labeled block in the stated order. Examples labeled Python, shell or HTTP belong in that client, not in a SQL editor. - Compare values and row counts with the explained result. If an example deliberately causes an error, follow its rollback and cleanup steps before continuing.
- SELECT / FROM
- Choose the values to return / identify their input.
- VALUES / COLUMN1
- VALUES supplies tiny example rows. COLUMN1 means their first column, COLUMN2 their second.
- AS / WITH
- AS gives a result a readable name. WITH names a temporary query step within one statement.
- NULL / ::
- NULL means missing or unknown. The :: notation converts a value to a named data type.
- Session
- One connection and its settings. Keep related transaction steps in the same session.
- Database.schema.table
- A full address for stored data. It is separate from the warehouse that processes queries.
Need the L2_OBJECTS_LAB setup? Open the first database-object lesson →
Help with common practice errors
- No active warehouse: select a warehouse your role can use. Do not assume you need to create a new one.
- Object missing or not authorized: check the full name, required setup and active role. Ask the account owner for access if needed.
- Object already exists: setup may already have run. Read the current state or choose a fresh lab name consistently; do not add OR REPLACE blindly.
- Different result: check whether an earlier INSERT or UPDATE changed the data. VALUES examples provide their own fresh input for each statement.
Before running this lesson
Manual learning lab; nothing runs on this website. Complete lesson 1 setup in L2_OBJECTS_LAB.M11_LAB and follow the lesson order. Use the same authorized role and warehouse for manual SQL. Task templates use <lab_warehouse>: replace it with an approved warehouse name. Do not activate several consumers against the same stream. Each task starts suspended; running or resuming it can consume compute credits.
Define an alternative graph, not a second concurrent consumer
ALTER TASK PROCESS_EVENTS SUSPEND;
-- First confirm PROCESS_EVENTS has no running execution.
CREATE TASK PIPELINE_ROOT WAREHOUSE=<lab_warehouse> SCHEDULE='5 MINUTE'
OVERLAP_POLICY=NO_OVERLAP TASK_AUTO_RETRY_ATTEMPTS=1
WHEN SYSTEM$STREAM_HAS_DATA('L2_OBJECTS_LAB.M11_LAB.EVENT_CHANGES')
AS CALL L2_OBJECTS_LAB.M11_LAB.APPLY_EVENTS(FALSE);
CREATE TASK PIPELINE_OBSERVE WAREHOUSE=<lab_warehouse> AFTER PIPELINE_ROOT
AS INSERT INTO L2_OBJECTS_LAB.M11_LAB.TASK_RUN_LOG VALUES ('root succeeded',CURRENT_TIMESTAMP());
CREATE TASK PIPELINE_FINISH WAREHOUSE=<lab_warehouse> FINALIZE=PIPELINE_ROOT
AS INSERT INTO L2_OBJECTS_LAB.M11_LAB.TASK_RUN_LOG VALUES ('graph ended; inspect history',CURRENT_TIMESTAMP());What to expect and why
All tasks start suspended. The observation label records predecessor success, while the finalizer deliberately does not claim successful business processing.
Run one graph after enabling its dependents
ALTER TASK PIPELINE_OBSERVE RESUME;
ALTER TASK PIPELINE_FINISH RESUME;
INSERT INTO ORDER_EVENTS VALUES (7,102,2,'UPSERT',55);
EXECUTE TASK PIPELINE_ROOT;
-- Wait for terminal task-history states before checking:
SELECT ORDER_ID,AMOUNT FROM ORDER_STATE WHERE NOT IS_DELETED ORDER BY ORDER_ID;What to expect and why
After root success the active rows are 102/55 and 103/75, total 130. Child/finalizer completion must be checked separately. The root remains suspended from recurring scheduling.
Check your understanding
Choose an answer, then check your reasoning. This is practice, not a scored test.
Try it yourself
Why should the finalizer log not say pipeline succeeded unconditionally?
Compare your reasoning
A finalizer can run after a failure. Determine success from task history and business reconciliation.