{"id":106202,"date":"2025-05-09T19:02:59","date_gmt":"2025-05-09T19:02:59","guid":{"rendered":"https:\/\/www.red-gate.com\/simple-talk\/?p=106202"},"modified":"2025-05-11T13:26:03","modified_gmt":"2025-05-11T13:26:03","slug":"parentchildtaskautomationinsnowflakeviataskgraph","status":"publish","type":"post","link":"https:\/\/www.red-gate.com\/simple-talk\/databases\/snowflake\/parentchildtaskautomationinsnowflakeviataskgraph\/","title":{"rendered":"Parent \u2013 Child Task Automation in Snowflake via Task Graph"},"content":{"rendered":"\n<h1 class=\"wp-block-heading\" id=\"h-\"><\/h1>\n\n\n\n<p>In the fast-paced world of business, fast, effective data management is crucial. One of the places where this is the most evident is in the healthcare sector. From patient records to treatment data, every piece of information must be processed accurately and efficiently. But how do you ensure that each step of the data flow is executed in the right order, and errors are handled effectively? Enter Snowflake&#8217;s <strong>Parent-Child Tasks<\/strong>.<\/p>\n\n\n\n<p>This article explores how to use <a href=\"https:\/\/docs.snowflake.com\/en\/user-guide\/tasks-intro\">Snowflake\u2019s task<\/a> features to implement <strong>parent-child data workflows<\/strong>. We will walk through a real-world scenario in which a healthcare organization manages patient records using a sequence of tasks for <strong>data ingestion, transformation, enrichment, and reporting<\/strong>. By setting up <strong>parent-child tasks<\/strong>, we can automate and control these steps, ensuring that each task is executed only after the successful completion of its predecessor.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-what-is-a-task\"><a id=\"post-106202-_Toc193507316\"><\/a>What Is a Task ? <\/h2>\n\n\n\n<p>In <a href=\"https:\/\/www.snowflake.com\/en\/\">Snowflake<\/a>, in order to automate and schedule the business process we will utilize the <a href=\"https:\/\/docs.snowflake.com\/en\/user-guide\/tasks-intro\">Task<\/a> feature<strong>. <\/strong>The Task infrastructure of Snowflake can run multiple types of resources such as:<\/p>\n\n\n<div class=\"block-core-list\">\n<ul class=\"wp-block-list\">\n<li> Single SQL Statement <\/li>\n\n\n\n<li> Call to a <a href=\"https:\/\/docs.snowflake.com\/en\/developer-guide\/stored-procedure\/stored-procedures-overview\">Stored Procedure<\/a> <\/li>\n\n\n\n<li> Procedural logic using <a href=\"https:\/\/docs.snowflake.com\/en\/developer-guide\/snowflake-scripting\/index\">Snowflake Scripting<\/a> <\/li>\n<\/ul>\n<\/div>\n\n\n<p>In this article, we will be using multiple tasks to call stored procedures to establish parent \u2013 child task relationships. To coordinate these tasks, we will be utilizing the <a href=\"https:\/\/docs.snowflake.com\/en\/user-guide\/tasks-graphs\">Task Graph<\/a> featured in snowflake to create sequences of tasks to implement a data pipeline for ingestion, transformation, enrichment and report generation.<\/p>\n\n\n\n<p>The <a href=\"https:\/\/docs.snowflake.com\/en\/sql-reference\/sql\/create-task\">CREATE TASK<\/a> statement will be used to create new tasks. You can see the syntax by following the link to the documentation. There are a lot of settings, many of which we will not touch on in this article.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-what-is-parent-child-task-aka-task-dependencies\"><a id=\"post-106202-_Toc193507317\"><\/a>What Is Parent \u2013 Child Task aka (Task dependencies)? <\/h2>\n\n\n\n<p>A task graph can be used to create what are commonly referred to as parent-child tasks. A parent \u2013 child task is the sequence of events where child task (<a href=\"https:\/\/docs.snowflake.com\/en\/sql-reference\/functions\/task_dependents\">dependent task<\/a>) only execute after the parent task (<a href=\"https:\/\/docs.snowflake.com\/en\/sql-reference\/functions\/task_dependents\">root task<\/a>) is completed it is job. It is commonly used in data engineering world to have data integrity within the tables. The relationship between the tasks are referred to as <a href=\"https:\/\/docs.snowflake.com\/en\/user-guide\/streams-intro\">task dependencies<\/a>, which is shown in the following diagram.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1429\" height=\"556\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2025\/04\/word-image-106202-1.png\" alt=\"\" class=\"wp-image-106203\" srcset=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2025\/04\/word-image-106202-1.png 1429w, https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2025\/04\/word-image-106202-1-300x117.png 300w, https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2025\/04\/word-image-106202-1-1024x398.png 1024w, https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2025\/04\/word-image-106202-1-768x299.png 768w\" sizes=\"auto, (max-width: 1429px) 100vw, 1429px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-parent-task\"><a id=\"post-106202-_Toc193507318\"><\/a>Parent Task <\/h3>\n\n\n\n<p>This will be the starting point (or the root of the graph) of the data pipeline workflow which can be executed to call <code>SP1<\/code> (stored procedure 1). In this article, <code>SP1<\/code> <code>PREPROCESS_HEALTHCARE_LOGS<\/code> will be used for pre-processing purpose to <strong>update the log table for removing null,<\/strong> so it can be ready for transformation in child task <code>2 HEALTHCARE_TRANSFORMATION_TASK<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-child-task-1\"><a id=\"post-106202-_Toc193507319\"><\/a>Child Task 1<\/h3>\n\n\n\n<p>Once the data ingesting and cleaning is completed from parent task <code>HEALTHCARE_PREPROCESSING_TASK<\/code>, the next task which is our child task 1 <code>HEALTHCARE_TRANSFORMATION_TASK<\/code> to call SP2 (stored procedure 2). The SP2 <code>TRANSFORM_HEALTHCARE_DATA<\/code> will basically perform transformation such as <strong>categorizing the patient event<\/strong>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-child-task-2\">Child Task 2<\/h3>\n\n\n\n<p>After completing cleaning and transformation task with SP1 <code>PREPROCESS_HEALTHCARE_LOGS<\/code> and SP2 <code>TRANSFORM_HEALTHCARE_DATA<\/code> respectively, our next action item is to add the data. Therefore, child task 2 <code>HEALTHCARE_ENRICHMENT_TASK<\/code> will call SP3 (Stored Procedure 3). In Stored Procedure 3 SP3 <code>ENRICH_HEALTHCARE_DATA<\/code> we will be <strong>adding provider details<\/strong>, providers are basically the one who provide healthcare services to patients such as medication, surgery and medical devices.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-child-task-3\"><a id=\"post-106202-_Toc193507321\"><\/a>Child Task 3<\/h3>\n\n\n\n<p>In this final task, we would generate summary report based on processed and transform data. The child task 3 <code>HEALTHCARE_REPORTING_TASK<\/code> will call stored procedure 4 SP4 <code>GENERATE_HEALTHCARE_REPORTS<\/code> to <strong>produce final output<\/strong> of the healthcare data.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-parent-child-task-data-flow-or-task-graph-flow\"><a id=\"post-106202-_Toc193507322\"><\/a>Parent \u2013 Child Task Data Flow or Task Graph Flow<\/h2>\n\n\n\n<p>The below figure showing a parent \u2013 child task data flow (task graph flow) within the healthcare environment. It starts with preprocessing task via sp1 (stored procedure 1) <code>PREPROCESS_HEALTHCARE_LOGS<\/code> to clean and normalize data. Next, we will apply child task 1: transformation task with stored procedure: <code>TRANSFORM_HEALTHCARE_DATA<\/code> (sp2) to categorize patient events for data analytics. Furthermore, we will implement child task 2 and 3 with sp3 <code>ENRICH_HEALTHCARE_DATA<\/code> and <code>sp4<\/code> <code>GENERATE_HEALTHCARE_REPORTS<\/code> respectively, which will be utilized to insert additional data and producing final output for data analysis.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"508\" height=\"896\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2025\/04\/word-image-106202-2.png\" alt=\"\" class=\"wp-image-106204\" srcset=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2025\/04\/word-image-106202-2.png 508w, https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2025\/04\/word-image-106202-2-170x300.png 170w\" sizes=\"auto, (max-width: 508px) 100vw, 508px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-parent-child-task-implementation\"><a id=\"post-106202-_Toc193507323\"><\/a>Parent Child Task Implementation <\/h2>\n\n\n\n<p>In this section, we will perform step-by-step process for <strong>task (parent \u2013 child)<\/strong> implementation in Snowflake. We will start with creation of database which we have already covered in this <a href=\"https:\/\/www.red-gate.com\/simple-talk\/databases\/snowflake\/change-data-capture-pipeline-automation-in-snowflake\/\">article<\/a>. Afterwards, we will start with the development of 4 <strong>stored procedures<\/strong> along with the relationship reasoning of <a href=\"https:\/\/docs.dataops.live\/docs\/guides\/how-to\/use-parent-child-pipelines\/\"><strong>parent child concept<\/strong><\/a><strong> <\/strong>within this article. We then progress to setup <a href=\"https:\/\/docs.snowflake.com\/en\/user-guide\/tasks-graphs\">task graph<\/a> with parent-child built in feature from SQL to automate the store procedures, as a result, it will create out final output, <code>Daily_Reports<\/code><strong>.<\/strong><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-stored-procedures-creation\"><a id=\"post-106202-_Toc193507324\"><\/a>Stored Procedures Creation <\/h3>\n\n\n\n<p>We will build a healthcare <a href=\"https:\/\/docs.snowflake.com\/en\/sql-reference\/sql\/create-database&quot; \\l &quot;general-usage-notes\">database in Snowflake<\/a> at this stage. Start by creating a new database:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"934\" height=\"317\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2025\/04\/https-www-red-gate-com-simple-talk-wp-content-up.png\" alt=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2024\/07\/word-image-103280-2.png\" class=\"wp-image-106205\" srcset=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2025\/04\/https-www-red-gate-com-simple-talk-wp-content-up.png 934w, https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2025\/04\/https-www-red-gate-com-simple-talk-wp-content-up-300x102.png 300w, https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2025\/04\/https-www-red-gate-com-simple-talk-wp-content-up-768x261.png 768w\" sizes=\"auto, (max-width: 934px) 100vw, 934px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>The two tables represented in the following screenshot can be created and <a href=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2025\/04\/Parent-Child-Task-Automation-in-Snowflake-via-Task-Graph-Code-to-reset-demo.zip\">populated from this SQL file<\/a> if you want to follow along on Snowflake.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"330\" height=\"108\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2025\/04\/word-image-106202-4.png\" alt=\"\" class=\"wp-image-106206\" srcset=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2025\/04\/word-image-106202-4.png 330w, https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2025\/04\/word-image-106202-4-300x98.png 300w\" sizes=\"auto, (max-width: 330px) 100vw, 330px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>We will proceed to create four stored procedures represented on the following diagram that will be used for various purposes when processing our data.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"2349\" height=\"692\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2025\/04\/word-image-106202-5.png\" alt=\"\" class=\"wp-image-106207\" srcset=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2025\/04\/word-image-106202-5.png 2349w, https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2025\/04\/word-image-106202-5-300x88.png 300w, https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2025\/04\/word-image-106202-5-1024x302.png 1024w, https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2025\/04\/word-image-106202-5-768x226.png 768w, https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2025\/04\/word-image-106202-5-1536x452.png 1536w, https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2025\/04\/word-image-106202-5-2048x603.png 2048w\" sizes=\"auto, (max-width: 2349px) 100vw, 2349px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"h-sp1-preprocess-healthcare-logs\"><a id=\"post-106202-_Toc193507325\"><\/a>SP1 preprocess_healthcare_logs<\/h4>\n\n\n\n<p>Create the procedure by using following code:<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"block lang:tsql\" highlight=\"true\" decode=\"true\">CREATE OR REPLACE PROCEDURE PREPROCESS_HEALTHCARE_LOGS()\nRETURNS STRING\nLANGUAGE SQL\nAS\n$\nBEGIN\n-- Ensure timestamps are properly formatted\nUPDATE HEALTHCARE_LOGS\nSET EVENT_TIME = TO_TIMESTAMP(EVENT_TIME)\nWHERE EVENT_TIME IS NOT NULL;\n\n-- Remove incomplete records\nDELETE FROM HEALTHCARE_LOGS WHERE PROVIDER_ID IS NULL;\n\nRETURN 'Preprocessing Completed';\nEND;\n$;<\/pre><\/div>\n\n\n\n<p>In the above code, we will ensure timestamps are correctly formatted using a standard format (<code>YYYY-MM-DD HH24:MI:SS<\/code>), it transforms the <code>EVENT_TIME<\/code> column into the appropriate <code>TIMESTAMP<\/code> data type. This is crucial because date values are frequently entered as plain text by raw ingestion processes, which, if improperly formatted, can lead to problems when sorting, filtering, or time-based aggregations.<\/p>\n\n\n\n<p>Secondly, we will be removing NULL values from provider information is null because we want accurate reporting for healthcare compliance <\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"h-sp2-transform-healthcare-data\"> <a id=\"post-106202-_Toc193507326\"><\/a>SP2 transform_healthcare_data <\/h4>\n\n\n\n<p>Create the procedure by using following code:<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"block lang:tsql\" highlight=\"true\" decode=\"true\">CREATE OR REPLACE PROCEDURE transform_healthcare_data()\nRETURNS STRING\nLANGUAGE SQL\nAS\n$\nBEGIN\n    -- Example: Categorize patient events based on type\n    UPDATE Healthcare_LOGS\n    SET PATIENT_EVENT = CASE\n        WHEN PATIENT_EVENT LIKE '%Checkup%' THEN 'Routine Checkup'\n        WHEN PATIENT_EVENT LIKE '%Surgery%' THEN 'Surgical Procedure'\n        WHEN PATIENT_EVENT LIKE '%Emergency%' THEN 'Emergency Procedure'\n        ELSE 'General Consultation'\n    END;\n    RETURN 'Transformation completed successfully';\nEND;\n$;<\/pre><\/div>\n\n\n\n<p style=\"padding-right:0;padding-left:var(--wp--preset--spacing--md)\"><em>Note: For demonstration purposes, this transformation overwrites the original <\/em><code>PATIENT_EVENT<\/code><em> value. In a production environment, it is advisable to write categorized values to a separate column to preserve the original data.<\/em><\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"h-sp3-enrich-healthcare-data\"><a id=\"post-106202-_Toc193507327\"><\/a>SP3 enrich_healthcare_data<\/h4>\n\n\n\n<p>Create the procedure by using following code. This procedure enriches the data, which in this sample case is just updating the <code>PROVIDER_ID<\/code> value to the same value (which basically validates that the <code>Healthcare_LOGS.PROVIDER_ID<\/code> value is in the <code>ProviderDirectory<\/code> table), but typically you might be pulling in additional columns.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"block lang:tsql\" highlight=\"true\" decode=\"true\">CREATE OR REPLACE PROCEDURE enrich_healthcare_data()\nRETURNS STRING\nLANGUAGE SQL\nAS\n$\nBEGIN\n    -- Example: Enrich data with provider details\n    UPDATE Healthcare_LOGS AS H\n    SET H.PROVIDER_ID = p.PROVIDER_ID\n    FROM (SELECT PROVIDER_ID --, PROVIDER_NAME\n          FROM Provider_Directory) p\n    WHERE h.PROVIDER_ID = p.PROVIDER_ID;\n\n    RETURN 'Enrichment completed successfully';\nEND;\n$;<\/pre><\/div>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"h-sp4-generate-healthcare-reports\"><a id=\"post-106202-_Toc193507328\"><\/a>SP4 generate_healthcare_reports<\/h4>\n\n\n\n<p>Create the procedure by using following code. This code will create the report table by creating or recreating the Daily_Reports object using the data that has been manipulated in the previous steps.:<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"block lang:tsql\" highlight=\"true\" decode=\"true\">CREATE OR REPLACE PROCEDURE generate_healthcare_reports()\nRETURNS STRING\nLANGUAGE SQL\nAS\n$\nBEGIN\n    -- Example: Aggregate data to create daily reports\n    CREATE OR REPLACE TABLE Daily_Reports AS\n    SELECT\n        DATE_TRUNC('day', EVENT_TIME) AS Report_Date,\n        COUNT(*) AS Total_Events,\n        COUNT(DISTINCT PATIENT_ID) AS Unique_Patients\n    FROM Healthcare_LOGS\n    GROUP BY DATE_TRUNC('day', EVENT_TIME);\n    RETURN 'Reports generated successfully';\nEND;\n$;<\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-automating-stored-procedures-via-task-graph-parent-child-task\"><a id=\"post-106202-_Toc193507329\"><\/a>Automating Stored Procedures via Task Graph (Parent \u2013 Child Task) <\/h3>\n\n\n\n<p>After creating the stored procedures, the next step is to create the task for each store procedure to create a parent \u2013 child process. The stored procedures <a href=\"https:\/\/docs.dataops.live\/docs\/guides\/how-to\/use-parent-child-pipelines\/\">relationship within the parent-child concept<\/a> in Snowflake tasks, as applied to our content (the healthcare data processing workflow), is fundamentally about <a href=\"https:\/\/docs.snowflake.com\/en\/user-guide\/streams-intro\">task dependencies<\/a> and the <a href=\"https:\/\/www.chaosgenius.io\/blog\/automate-sql-snowflake-tasks\/\">sequential execution<\/a> of stored procedures, where each task (child) depends on the successful completion of the previous task (parent).<\/p>\n\n\n\n<p>In the context of a healthcare data pipeline, processing patient records in stages such as preprocessing, transformation, enrichment, and reporting is crucial. In a real-world scenario, these stages must be executed sequentially to ensure the integrity of the data at each step.<\/p>\n\n\n\n<p>Therefore, snowflake\u2019s <a href=\"https:\/\/docs.snowflake.com\/en\/user-guide\/tasks-graphs\">task graph<\/a><strong> <\/strong>built with parent-child task offer a seamless way to automate these workflows. These tasks are executed sequentially, ensuring that each task completes before the next begins, thus preserving the logical flow of the data pipeline.<\/p>\n\n\n\n<p>Here\u2019s how we break down the automation process using task graphs:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1299\" height=\"755\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2025\/04\/word-image-106202-6.png\" alt=\"\" class=\"wp-image-106208\" srcset=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2025\/04\/word-image-106202-6.png 1299w, https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2025\/04\/word-image-106202-6-300x174.png 300w, https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2025\/04\/word-image-106202-6-1024x595.png 1024w, https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2025\/04\/word-image-106202-6-768x446.png 768w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"h-define-the-root-task-preprocessing\"><a id=\"post-106202-_Toc193507330\"><\/a>Define the Root Task (Preprocessing)<\/h4>\n\n\n\n<p>The root task is responsible for the initial preprocessing of healthcare logs from stored procedure <code>preprocess_healthcare_logs<\/code><strong>. <\/strong><\/p>\n\n\n\n<p>Create the task by using following code:<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"block lang:tsql\" highlight=\"true\" decode=\"true\">CREATE OR REPLACE TASK healthcare_preprocessing_task\nWAREHOUSE = 'compute_wh'\nSCHEDULE = '10 MINUTE'\nAS\nCALL preprocess_healthcare_logs();<\/pre><\/div>\n\n\n\n<p>In the task creation, there are a few parameters that have been defined.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"block lang:tsql\" highlight=\"true\" decode=\"true\">WAREHOUSE = 'compute_wh'<\/pre><\/div>\n\n\n\n<p>Specifies the virtual warehouse to execute the task. This user-managed warehouse provides the compute power needed to run the SQL in our procedure.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"block lang:tsql\" highlight=\"true\" decode=\"true\">SCHEDULE = '10 MINUTE'<\/pre><\/div>\n\n\n\n<p>This defines how often the task should run \u2014 every 10 minutes. It ensures our data is cleaned regularly without needing manual intervention.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"block lang:tsql\" highlight=\"true\" decode=\"true\">CALL preprocess_healthcare_logs();<\/pre><\/div>\n\n\n\n<p>Invokes the stored procedure that standardizes date formats and removes invalid records (like null patient IDs) from our Healthcare_LOGS table.<\/p>\n\n\n\n<p><strong>What Happens if this Task Graph Takes Longer Than 10 Minutes?<\/strong><\/p>\n\n\n\n<p>Snowflake tasks do not overlap by default. If the task hasn\u2019t finished before the next scheduled start, that run will be skipped. This helps avoid data conflicts, but repeated skips may cause processing delays. Hence it is good to monitor your processes to make sure that you have the interval time set to a reasonable level.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"h-create-the-first-child-task-transformation\"><a id=\"post-106202-_Toc193507331\"><\/a>Create the First Child Task (Transformation)<\/h4>\n\n\n\n<p>Once the preprocessing task is complete, the transformation task takes over. This task uses the results of the preprocessing step and categorizes the patient data from <code>transform_healthcare_data<\/code><strong> <\/strong><\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"block lang:tsql\" highlight=\"true\" decode=\"true\">CREATE OR REPLACE TASK healthcare_transformation_task\nWAREHOUSE = 'compute_wh'\nAFTER healthcare_preprocessing_task\nAS\nCALL transform_healthcare_data();<\/pre><\/div>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"h-create-the-second-child-task-enrichment\"><a id=\"post-106202-_Toc193507332\"><\/a>Create the Second Child Task (Enrichment)<\/h4>\n\n\n\n<p>The transformation task is followed by the enrichment task (<code>enrich_healthcare_data<\/code>), which pulls in external data like provider details.<\/p>\n\n\n\n<p>Create the task by using following code:<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"block lang:tsql\" highlight=\"true\" decode=\"true\">CREATE OR REPLACE TASK healthcare_enrichment_task\nWAREHOUSE = 'compute_wh'\nAFTER healthcare_transformation_task\nAS\nCALL enrich_healthcare _data();<\/pre><\/div>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"h-create-the-final-child-task-reporting\"><a id=\"post-106202-_Toc193507333\"><\/a>Create the Final Child Task (Reporting)<\/h4>\n\n\n\n<p>The final step is to generate healthcare reports from stored procedure <code>generate_healthcare_reports<\/code><strong>.<\/strong> This task only runs after the data has been enriched.<\/p>\n\n\n\n<p>Create the task by using following code:<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"block lang:tsql\" highlight=\"true\" decode=\"true\">CREATE OR REPLACE TASK healthcare_reporting_task\nWAREHOUSE = 'compute_wh'\nAFTER healthcare_enrichment_task\nAS\nCALL generate_healthcare_reports();<\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-task-monitoring-and-report-verification\"><a id=\"post-106202-_Toc193507334\"><\/a>Task Monitoring and Report Verification<\/h3>\n\n\n\n<p>Before executing the sequence of tasks created above. Let\u2019s examine our <code>healthcare_logs<\/code> table before making any updates.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"753\" height=\"182\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2025\/04\/word-image-106202-7.png\" alt=\"\" class=\"wp-image-106209\" srcset=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2025\/04\/word-image-106202-7.png 753w, https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2025\/04\/word-image-106202-7-300x73.png 300w\" sizes=\"auto, (max-width: 753px) 100vw, 753px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Next, navigate to the task list to see the list of tasks. Note that tasks are in suspended state by default. So we will need to enable them.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"358\" height=\"284\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2025\/04\/word-image-106202-8.png\" alt=\"\" class=\"wp-image-106210\" srcset=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2025\/04\/word-image-106202-8.png 358w, https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2025\/04\/word-image-106202-8-300x238.png 300w\" sizes=\"auto, (max-width: 358px) 100vw, 358px\" \/><\/figure>\n\n\n\n<p>\n  \n  <br>\n<\/p>\n\n\n\n<p>Once we click on graph section on <strong>DEMO_HEALTHCARE \/PUBLIC \/ HEALTHCARE_PREPROCESSING_TASK <\/strong>you can see it is the root task which we have developed above.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1202\" height=\"401\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2025\/04\/word-image-106202-9.png\" alt=\"\" class=\"wp-image-106211\" srcset=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2025\/04\/word-image-106202-9.png 1202w, https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2025\/04\/word-image-106202-9-300x100.png 300w, https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2025\/04\/word-image-106202-9-1024x342.png 1024w, https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2025\/04\/word-image-106202-9-768x256.png 768w\" sizes=\"auto, (max-width: 1202px) 100vw, 1202px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>In order to navigate to child task we can navigate to <strong>DEMO_HEALTHCARE \/PUBLIC \/ HEALTHCARE_TRANSFORMATION_TASK<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1228\" height=\"533\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2025\/04\/word-image-106202-10.png\" alt=\"\" class=\"wp-image-106212\" srcset=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2025\/04\/word-image-106202-10.png 1228w, https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2025\/04\/word-image-106202-10-300x130.png 300w, https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2025\/04\/word-image-106202-10-1024x444.png 1024w, https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2025\/04\/word-image-106202-10-768x333.png 768w\" sizes=\"auto, (max-width: 1228px) 100vw, 1228px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>After examining the pre-task execution, now, the next step is to restart it. Snowflake tasks are stopped by default when created and must be explicitly resumed to become active. Do this by executing the following script:<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"font-size:13 lang:tsql decode:true block\">SELECT SYSTEM$TASK_DEPENDENTS_ENABLE('DEMO_HEALTHCARE.PUBLIC.HEALTHCARE_PREPROCESSING_TASK');<\/pre><\/div>\n\n\n\n<p>Now you can start the tasks as noted. Then after executing all the tasks, the next thing to do is to verify the task execution. Now let\u2019s proceed to monitor the task which we have executed. In <a href=\"https:\/\/docs.snowflake.com\/en\/user-guide\/ui-snowsight\">Snowsight<\/a>, the snowflake web interface, you can easily visualize and monitor task graphs:<\/p>\n\n\n\n<p>Navigate to the <strong>Tasks<\/strong> section in Snowsight.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"428\" height=\"344\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2025\/04\/word-image-106202-11.png\" alt=\"\" class=\"wp-image-106213\" srcset=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2025\/04\/word-image-106202-11.png 428w, https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2025\/04\/word-image-106202-11-300x241.png 300w\" sizes=\"auto, (max-width: 428px) 100vw, 428px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Here, you will see all active tasks and their respective statuses. For parent-child tasks, the interface shows the relationship between tasks in a tree structure, allowing you to view dependencies.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1142\" height=\"169\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2025\/04\/word-image-106202-12.png\" alt=\"\" class=\"wp-image-106214\" srcset=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2025\/04\/word-image-106202-12.png 1142w, https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2025\/04\/word-image-106202-12-300x44.png 300w, https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2025\/04\/word-image-106202-12-1024x152.png 1024w, https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2025\/04\/word-image-106202-12-768x114.png 768w\" sizes=\"auto, (max-width: 1142px) 100vw, 1142px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>You can view details like the <strong>last execution time<\/strong>, <strong>status<\/strong> (Success, Failed, or Skipped), and the <strong>scheduled interval<\/strong>.`<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"615\" height=\"509\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2025\/04\/word-image-106202-13.png\" alt=\"\" class=\"wp-image-106215\" srcset=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2025\/04\/word-image-106202-13.png 615w, https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2025\/04\/word-image-106202-13-300x248.png 300w\" sizes=\"auto, (max-width: 615px) 100vw, 615px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Prior to the task graph status as \u201csucceeded\u201d, we have received failure as well, when executing the task with the following error.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"748\" height=\"238\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2025\/04\/word-image-106202-14.png\" alt=\"\" class=\"wp-image-106216\" srcset=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2025\/04\/word-image-106202-14.png 748w, https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2025\/04\/word-image-106202-14-300x95.png 300w\" sizes=\"auto, (max-width: 748px) 100vw, 748px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p style=\"padding-right:0;padding-left:var(--wp--preset--spacing--md)\"><em>Note: This is an error I forced to occur by changing the stored procedure to reference H.PROVIDER_NAME, which does not exist in the table.<\/em><\/p>\n\n\n\n<p>We double click on latest scheduled run time, it will open the task graph:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1098\" height=\"394\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2025\/04\/word-image-106202-15.png\" alt=\"\" class=\"wp-image-106217\" srcset=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2025\/04\/word-image-106202-15.png 1098w, https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2025\/04\/word-image-106202-15-300x108.png 300w, https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2025\/04\/word-image-106202-15-1024x367.png 1024w, https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2025\/04\/word-image-106202-15-768x276.png 768w\" sizes=\"auto, (max-width: 1098px) 100vw, 1098px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>As you have noticed, all the task&#8217;s status is \u201c<strong>Succeeded<\/strong>\u201d.<\/p>\n\n\n\n<p>In the next step, we will check the data was populated for the report by the stored procedure SP4 <code>generate_healthcare_reports<\/code> via the <code>healthcare_reporting_task<\/code> task<strong>. <\/strong>To do this, I will execute the following query.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"block lang:tsql\" highlight=\"true\" decode=\"true\">select * \nfrom DEMO_HEALTHCARE. PUBLIC. DAILY_REPORTS<\/pre><\/div>\n\n\n\n<p>The output should look something like the following:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"504\" height=\"285\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2025\/04\/word-image-106202-16.png\" alt=\"\" class=\"wp-image-106218\" srcset=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2025\/04\/word-image-106202-16.png 504w, https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2025\/04\/word-image-106202-16-300x170.png 300w\" sizes=\"auto, (max-width: 504px) 100vw, 504px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-conclusion\"><a id=\"post-106202-_Toc193507335\"><\/a>Conclusion<\/h2>\n\n\n\n<p>In this article, we focused on how to automate and simplify the processing of healthcare data by implementing parent-child tasks in Snowflake. We began by discovering tasks and how parent-child relationships enable the correct execution sequence of stored procedures.<\/p>\n\n\n\n<p>Firstly, in order to ensure accuracy and efficiency, we built stored procedures for preprocessing <strong><em>SP1 <\/em><\/strong><code>preprocess_healthcare_logs<\/code><strong><em>,<\/em> <\/strong>transformation <strong><em>SP2 <\/em><\/strong><code>transform_healthcare_data<\/code><strong><em> <\/em><\/strong> , enrichment <strong><em>SP3 <\/em><\/strong><code>enrich_healthcare_data<\/code><strong><em>,<\/em><\/strong> and reporting <strong><em>SP4 <\/em><\/strong><code>generate_healthcare_reports<\/code>, which are the various steps of the data pipeline.<\/p>\n\n\n\n<p>We then discussed about task graphs, which show the connections between parent-child task in an organized workflow graphically. We processed healthcare data step-by-step by automating the execution of stored processes using parent-child dependencies via SQL scripting.<\/p>\n\n\n\n<p>This process shows that Snowflake can effectively manage patient data, making it easier for healthcare providers to access the latest and most accurate information.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In the fast-paced world of business, fast, effective data management is crucial. One of the places where this is the most evident is in the healthcare sector. From patient records to treatment data, every piece of information must be processed accurately and efficiently. But how do you ensure that each step of the data flow&#8230;&hellip;<\/p>\n","protected":false},"author":343433,"featured_media":106221,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[53,159001],"tags":[159123],"coauthors":[159125],"class_list":["post-106202","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-featured","category-snowflake","tag-snowflake"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/106202","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/users\/343433"}],"replies":[{"embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/comments?post=106202"}],"version-history":[{"count":4,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/106202\/revisions"}],"predecessor-version":[{"id":106227,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/106202\/revisions\/106227"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/media\/106221"}],"wp:attachment":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/media?parent=106202"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/categories?post=106202"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/tags?post=106202"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/coauthors?post=106202"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}