TASKS
Description
Table function, generates a temporary table of tasks, which allows you to view the information of tasks generated by jobs in the current Doris cluster.
Syntax
TASKS(
"type"="<type>"
)
Parameters
| Parameter | Description |
|---|---|
<type> | Type of the task: insert: insert into type task. mv: materialized view type task. |
Return Value
This table function returns zero or more rows. The function itself does not return NULL. Individual fields can be empty, NULL, or \N when the corresponding task metadata is unavailable.
-
tasks("type"="insert")tasks return value of type insertField Name Description TaskId Task id JobId Job id JobName Job name Label Label Status Task status ErrorMsg Task failure information CreateTime Task creation time FinishTime Task completion time TrackingUrl Tracking URL LoadStatistic Load statistics User User -
tasks("type"="mv")tasks return value of type MVField Name Description TaskId Unique ID of the refresh task. Each materialized view refresh creates a new task record. JobId ID of the job that generated this task. It corresponds to jobs("type"="mv").Id.JobName Name of the job that generated this task. It corresponds to mv_infos("database"="...").JobNameandjobs("type"="mv").Name.MvId ID of the materialized view refreshed by this task. MvName Name of the materialized view refreshed by this task. MvDatabaseId ID of the database that contains the materialized view. MvDatabaseName Name of the database that contains the materialized view. Status Task status. Possible values: PENDINGmeans the task is waiting to run;RUNNINGmeans the task is running;SUCCESSmeans the task finished successfully;FAILEDmeans the task failed;CANCELEDmeans the task was canceled.ErrorMsg Error message when StatusisFAILEDorCANCELED. Empty when the task succeeds.CreateTime Time when the task record was created. StartTime Time when the task started running. It can be \Nif the task has not started.FinishTime Time when the task finished. It can be \Nif the task is still pending or running.DurationMs Runtime in milliseconds, calculated as FinishTime - StartTime. It can be\Nif the task has not finished.TaskContext JSON string describing how the task was triggered and what the user requested. Common fields include triggerMode,partitions, andisComplete.triggerModevalues areMANUAL,COMMIT, andSYSTEM.RefreshMode Actual refresh scope decided by this task. Possible values: COMPLETEmeans all materialized view partitions were refreshed;PARTIALmeans only some partitions were refreshed;NOT_REFRESHmeans no partition needed refreshing.NeedRefreshPartitions JSON array of materialized view partitions that needed refreshing in this task. Empty array means no partition needed refreshing. CompletedPartitions JSON array of partitions that were refreshed successfully. Compare it with NeedRefreshPartitionsto see whether all required partitions completed.Progress Refresh progress in the format percentage (completed/total), for example100.00% (1/1). It can be\Nwhen there is no partition to refresh.LastQueryId Query ID of the SQL statement executed by the refresh task. Use this ID to search FE or BE logs when troubleshooting task failures. It can be empty when no refresh SQL was executed. This field is supported since Doris 3.0.0.
MV task enum fields
The following enum fields are commonly used when checking materialized view refresh tasks:
Status: lifecycle state of the task.PENDING: the task has been created but has not started running. It is waiting for scheduling or resources.RUNNING: the task is currently running.SUCCESS: the task finished successfully.FAILED: the task failed. CheckErrorMsgfirst, and useLastQueryIdto search logs if it is not empty.CANCELED: the task was canceled before it finished.
TaskContext.triggerMode: why this task was created.MANUAL: created by a manual refresh command, such asREFRESH MATERIALIZED VIEW.COMMIT: created because data changes on related base tables triggered refresh.SYSTEM: created by an internal system action, for example the initial build of a materialized view created with immediate build.
TaskContext.isComplete: whether the refresh request asks for a complete refresh.true: the request asks Doris to refresh all materialized view partitions.false: the request does not force complete refresh. Doris can decide the actual refresh scope based on partition freshness.
RefreshMode: actual refresh scope selected by the task after checking partitions.COMPLETE: all materialized view partitions that belong to the MV were selected for refresh.PARTIAL: only some materialized view partitions were selected for refresh.NOT_REFRESH: no partition needed refresh. In this case,NeedRefreshPartitionsis usually empty andProgresscan be\N.
LastQueryId is supported since Doris 3.0.0. It is not available in Doris 2.1.x.
Examples
View the latest refresh task of a materialized view.
select *
from tasks("type"="mv")
where MvDatabaseName = "test" and MvName = "mv1"
order by CreateTime desc
limit 1\G
*************************** 1. row ***************************
TaskId: 437156301250803
JobId: 19508
JobName: inner_mtmv_19494
MvId: 19494
MvName: mv1
MvDatabaseId: 16016
MvDatabaseName: test
Status: SUCCESS
ErrorMsg:
CreateTime: 2025-01-07 22:13:48
StartTime: 2025-01-07 22:13:48
FinishTime: 2025-01-07 22:17:45
DurationMs: 236985
TaskContext: {"triggerMode":"MANUAL","partitions":[],"isComplete":false}
RefreshMode: COMPLETE
NeedRefreshPartitions: ["p_20210101_MAXVALUE","p_20200101_20210101"]
CompletedPartitions: ["p_20210101_MAXVALUE","p_20200101_20210101"]
Progress: 100.00% (2/2)
LastQueryId: 7965b4ddce8a4480-8884e9701679c1c4
In this result:
TaskIdidentifies this refresh execution. It is different for every refresh.JobIdandJobNameidentify the MV refresh job. The job can be queried withselect * from jobs("type"="mv") where Name = "inner_mtmv_19494";.MvId,MvName,MvDatabaseId, andMvDatabaseNameidentify the materialized view refreshed by the task.StatusisSUCCESS, so the task finished successfully. If it isFAILED, checkErrorMsgfirst.CreateTime,StartTime,FinishTime, andDurationMsshow when the task was created, when it started, when it finished, and how long it ran.TaskContextshows this task was manually triggered.partitions: []means the user did not specify a partition list in the refresh command.RefreshModeisCOMPLETE, so this task refreshed all partitions that the materialized view had to refresh.NeedRefreshPartitionslists two partitions that needed refreshing, andCompletedPartitionslists the same two partitions, so all required partitions completed.Progressis100.00% (2/2), which also means two of two required partitions completed.LastQueryIdis the query ID of the refresh SQL. Use it to search Doris logs when the task fails or runs slowly.
The number of stored and displayed task records is controlled by the FE configuration item max_persistence_task_count. The default value is 100. When the number of task records exceeds this limit, older task records are discarded. If the value is less than 1, task records are not persisted. Restart FE after changing this configuration.
View tasks for all insert tasks
select * from tasks("type"="insert");
+----------------+----------------+----------------+-------------------------------+---------+----------+---------------------+---------------------+---------------------+-------------+---------------+------+
| TaskId | JobId | JobName | Label | Status | ErrorMsg | CreateTime | StartTime | FinishTime | TrackingUrl | LoadStatistic | User |
+----------------+----------------+----------------+-------------------------------+---------+----------+---------------------+---------------------+---------------------+-------------+---------------+------+
| 79133848479750 | 78533940810334 | insert_tab_job | 78533940810334_79133848479750 | SUCCESS | | 2025-01-17 14:42:54 | 2025-01-17 14:42:54 | 2025-01-17 14:42:54 | | | root |
+----------------+----------------+----------------+-------------------------------+---------+----------+---------------------+---------------------+---------------------+-------------+---------------+------+