Are you looking to find how to check the history of the task execution within the snowflake cloud data warehouse or maybe you are looking for a solution to the find the status of the old task execution runs. You may also want to check what could be the next schedule time of the task in Snowflake. In this article, I will take you through a step-by-step process of finding the task history and get the status of the task. After going through this article you will be able to know how to debug the task execution and identify, was there any issue with the task in the Snowflake. Let’s don’t waste the time and I will take you quickly to the code directly where I will show you how to check the task history.
To check the history of the task use below SQL query:
select * from table ( information_schema.task_history( [ SCHEDULED_TIME_RANGE_START => ] [, SCHEDULED_TIME_RANGE_END => ] [, RESULT_LIMIT => ] [, TASK_NAME => ” ] ))
- 1 Example to check Task History in Snowflake:
- 2 How to check the history of all the task in the Snowflake?
- 3 How to check the history of all the task executed in last one hour in the Snowflake?
- 4 How to check if snowflake task is not running?
- 5 What is the maximum number of rows can be return by Task_history query?
- 6 What could be the maximum date range for the task history?
- 7 How to check snowflake task status?
- 8 What are the different states of a Snowflake task?
- 9 How to get schedule task details only, from task history in Snowflake?
- 10 What are the list of the column return by Task_History function in Snowflake?
- 11 Final Thoughts
Example to check Task History in Snowflake:
-- This query will show the task history for last 1 hour for task name = Snowflake_task_name select * from table(information_schema.task_history( scheduled_time_range_start=>dateadd('hour',-1,current_timestamp()), result_limit => 10, task_name=>'Snowflake_task_name'))
How to check the history of all the task in the Snowflake?
In the Snowflake using the Task_history command we can retrieve the history for all the task. We have the option to provide the task name in the task history query. Once you not provide the task name within the Task_History, it will return the historical information for all the task.
Example query to check history of all the task in Snowflake
Query is follows:
select * from table(information_schema.task_history( result_limit => 100))
Above query will return last 100 task execution based on the timestamp.
How to check the history of all the task executed in last one hour in the Snowflake?
In the Snowflake using the Task_history command we can retrieve the history for all the task. We have the option to provide the task name in the task history query. Once you not provide the task name within the Task_History, it will return the historical information for all the task. However once you add the start time range as last one hour within the Task_History query then it will return all the task executed in last hour.
Example query to check history of all the task executed in last hour in Snowflake
Query is follows:
select * from table(information_schema.task_history( scheduled_time_range_start=>dateadd('hour',-1,current_timestamp()), result_limit => 100))
Above query will return last 100 task executed in last one hour.
How to check if snowflake task is not running?
There could be multiple reasons because that your Snowflask task might not be running.
There could be set of few possible reasons.
1. Your task’s SQL might be throwing some error.
2. Task’s parent task not executed yet.
3. Task in Suspended state
4. Task schedule time yet to arrive.
Let’s understand each reason in detail.
Task has been executed, but the SQL which is used within the task might have caused some exceptions. Hence this could be one of the reasons that’s why you are not able to see any changes.
You can verify the task execution history to check the whether any exception occurred or not. Run the task histroy query for the specific task which you want to analyze. Once you get the task history result just there STATE and ERROR CODE.
In case your task is failed then you will get the error code and there will be the reason mentioned in the error_message column. Now you can analyze the error message, make the changes and restart your task.
Task might be scheduled as the dependent task. In that case, it is possible that the parent task has not been executed due to which this task is not executed.
You can run the Task_history query to check the execution summary of the task. By this you will get know whether the task is executed yet or not. In case this case is dependent on other task, then check the Task history for the parent task.
There you will get to know whether there could be some issue with the parent task itself or not.
Your task might be in a suspended state that’s why it is not running. Again you can use the task history query to identify whether your task is scheduled to run or not.
What is the maximum number of rows can be return by Task_history query?
The maximum number of rows that can be returned by the task history query is 10000.
By default, the number of rows returned by the task history to query is 100 and we can have a range from 1 to 10000
What could be the maximum date range for the task history?
We can only get the task history for the past seven days. We cannot get the task history for more than the past 7 days same for the scheduled time as well. We can only get task schedule time detail for the next eight days.
How to check snowflake task status?
You can use the task history to get the task status. For example in the task history, you have to pass the task name and the time duration for which you want to check the status of the task. By this, you will get the complete detail of the task status like whether this has got succeeded failed, or canceled. You can find it by checking the state of the task.
What are the different states of a Snowflake task?
There could be five different states of the task as follows:
SUCCEEDED, FAILED, or CANCELLED, SCHEDULED, EXECUTING.
How to get schedule task details only, from task history in Snowflake?
Task history return multiple properties. One of the property or column name is Query_id. This query id represent the id for the query executed for the task. Hence if a task is not executed then query id will come out to be null only.
Hence to get only the scheduled task detail, you can use the where clause using the query_id = null.
-- Query to get only schedule task detail only using query_id null select * from table(information_schema.task_history( scheduled_time_range_start=>dateadd('hour',-1,current_timestamp()), result_limit => 10, task_name=>'My_Task_name')) where QUERY_ID is null
What are the list of the column return by Task_History function in Snowflake?
The list of the columns returned by the task_history function is as follows:
|Column Name||Data Type||Description|
|QUERY_ID||TEXT||ID of the SQL statement executed by the task.|
|NAME||TEXT||Name of the task.|
|DATABASE_NAME||TEXT||Name of the database that contains the task.|
|SCHEMA_NAME||TEXT||Name of the schema that contains the task.|
|QUERY_TEXT||TEXT||Text of the SQL statement.|
|CONDITION_TEXT||TEXT||Text of WHEN condition the task evaluates when determining whether to run.|
|STATE||TEXT||Status of the task: SCHEDULED, EXECUTING, SUCCEEDED, FAILED, or CANCELLED.|
|ERROR_CODE||NUMBER||Error code, if the statement returned an error.|
|ERROR_MESSAGE||TEXT||Error message, if the statement returned an error.|
|SCHEDULED_TIME||TIMESTAMP_LTZ||Time when the task is/was scheduled to start running. Note that we make a best effort to ensure absolute precision, but only guarantee that tasks do not execute before the scheduled time.|
|QUERY_START_TIME||TIMESTAMP_LTZ||Time when the query in the task definition started to run. This timestamp aligns with the start time for the query returned by QUERY_HISTORY.|
|NEXT_SCHEDULED_TIME||TIMESTAMP_LTZ||Time when the standalone or root task (in a tree of tasks) is next scheduled to start running, assuming the current run of the standalone task or tree of tasks started at the SCHEDULED_TIME time completes in time.|
|COMPLETED_TIME||TIMESTAMP_LTZ||Time when the task completed, or NULL if SCHEDULED_TIME is in the future or if the task is still running.|
|ROOT_TASK_ID||TEXT||Unique identifier for the root task in a tree of tasks. This ID matches the ID column value in the SHOW TASKS output for the same task.|
|GRAPH_VERSION||NUMBER||Integer identifying the version of the tree of tasks that was run, or is scheduled to be run. Each incremental increase in the value represents one or more modifications to tasks in the tree. If the root task is recreated (using CREATE OR REPLACE TASK), then the version number restarts from 1.|
|RUN_ID||NUMBER||Time when the standalone or root task in a tree of tasks is/was originally scheduled to start running.|
|RETURN_VALUE||TEXT||Value set for the predecessor task in a tree of tasks. The return value is explicitly set by calling the SYSTEM$SET_RETURN_VALUE function by the predecessor task.|
Snowflake official Documentation Link
By this, we have reached the end of our insightful article on how to check the history of the Snowflake task. In this article, we have learned how to check task history in the Snowflake. We have also gone through how you can check why Snowflake task is not running and what could be the possible reason or may be how you can debug. I have shared the practical Real-world scenarios which could be cause of failed task status in the Snowflake. I have already written one dedicated article on how to create task and how to schedule the task in case you have any queries on how to schedule the task please visit this blog to know much more about it.
Please share your comments and suggestions in the comment section below and I will try to answer all your queries as time permits.
- For Azure Study material Join Telegram group : Telegram group link:
- Azure Jobs and other updates Follow me on LinkedIn: Azure Updates on LinkedIn
- Azure Tutorial Videos: Videos Link
Deepak Goyal is certified Azure Cloud Solution Architect. He is having around decade and half experience in designing, developing and managing enterprise cloud solutions. He is also Big data certified professional and passionate cloud advocate.