Project: StarRocks (App Definition and Development / Database)
File: SUBMIT_TASK.md

displayed_sidebar: "English" Submits an ETL statement as an asynchronous task. You can use this statement to: execute long-running tasks in the background (supported from v2.5 onwards) schedule a task at a regular interval (supported from v3.3 onwards) Supported statements include: (from v3.0 onwards) (from v3.0 onwards) (from v3.3 onwards) You can view the list of tasks by querying `INFORMATIONSCHEMA.tasks`, or view the execution history of tasks by querying `INFORMATIONSCHEMA.task_runs`. For more information, see . You can drop an asynchronous task using . ```SQL SUBMIT TASK <task_name> [SCHEDULE [START(<schedulestart>)] EVERY(INTERVAL <scheduleinterval>) ] [PROPERTIES(<"key" = "value"[, ...]>)] AS <etl_statement> ``` | Parameter | Required | Description | | - | | - | | task_name | Yes | The name of the task. | | schedule_start | No | The start time for the scheduled task. | | schedule_interval | No | The interval at which the scheduled task is executed, with a minimum interval of 10 seconds. | | etl_statement | Yes | The ETL statement that you want to submit as an asynchronous task. StarRocks currently supports submitting asynchronous tasks for and . | This statement creates a Task, which is a template for storing a task that executes the ETL statement. You can check the information of the Task by querying the metadata view . ```SQL SELECT * FROM INFORMATION_SCHEMA.tasks; SELECT * FROM informationschema.tasks WHERE taskname = '<task_name>'; ``` After you run the Task, a TaskRun is generated accordingly. A TaskRun indicates a task that executes the ETL statement. A TaskRun has the following states: `PENDING`: The task waits to be run. `RUNNING`: The task is running. `FAILED`: The task failed. `SUCCESS`: The task runs successfully. You can check the state of a TaskRun by querying the metadata view . ```SQL SELECT * FROM INFORMATIONSCHEMA.taskruns; SELECT * FROM

WHERE taskname = '<taskname>'; ``` You can configure asynchronous ETL tasks using the following FE configuration items: | Parameter | Default value | Description | | - | -- | | | taskttlsecond | 86400 | The period during which a Task is valid. Unit: seconds. Tasks that exceed the validity period are deleted. | | taskcheckinterval_second | 3600 | The time interval to delete invalid Tasks. Unit: seconds. | | taskrunsttl_second | 86400 | The period during which a TaskRun is valid. Unit: seconds. TaskRuns that exceed the validity period are deleted automatically. Additionally, TaskRuns in the `FAILED` and `SUCCESS` states are also deleted automatically. | | taskrunsconcurrency | 4 | The maximum number of TaskRuns that can be run in parallel. | | taskrunsqueue_length | 500 | The maximum number of TaskRuns that are pending for running. If the number exceeds the default value, the incoming tasks will be suspended. | | taskrunsmaxhistorynumber | 10000 | The maximum number of TaskRun records to retain. | | taskminscheduleintervals | 10 | The minimum interval for Task execution. Unit: seconds. | Example 1: Submit an asynchronous task for `CREATE TABLE tbl1 AS SELECT * FROM src_tbl`, and specify the task name as `etl0`: ```SQL SUBMIT TASK etl0 AS CREATE TABLE tbl1 AS SELECT * FROM src_tbl; ``` Example 2: Submit an asynchronous task for `INSERT INTO tbl2 SELECT * FROM src_tbl`, and specify the task name as `etl1`: ```SQL SUBMIT TASK etl1 AS INSERT INTO tbl2 SELECT * FROM src_tbl; ``` Example 3: Submit an asynchronous task for `INSERT OVERWRITE tbl3 SELECT * FROM src_tbl`: ```SQL SUBMIT TASK AS INSERT OVERWRITE tbl3 SELECT * FROM src_tbl; ``` Example 4: Submit an asynchronous task for `INSERT OVERWRITE insertwikiedit SELECT * FROM sourcewikiedit` without specifying the task name, and extend the query timeout to `100000` seconds using the hint: ```SQL SUBMIT /+set_var(query_timeout=100000)/ TASK AS INSERT OVERWRITE insertwikiedit SELECT * FROM sourcewikiedit; ``` Example 5: Create an asynchronous task for an INSERT OVERWRITE statement. The task will be regularly executed at an interval of 1 minute. ```SQL SUBMIT TASK SCHEDULE EVERY(INTERVAL 1 MINUTE) AS INSERT OVERWRITE insertwikiedit SELECT dt, user_id, count(*) FROM sourcewikiedit GROUP BY dt, user_id; ```