> ## Documentation Index
> Fetch the complete documentation index at: /documents/llms.txt
> Use this file to discover all available pages before exploring further.

# SUBMIT TASK

> SUBMIT TASK submits an ETL statement as an asynchronous task.

SUBMIT TASK 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:

* [CREATE TABLE AS SELECT](/documents/4.2/sql-reference/sql-statements/table_bucket_part_index/CREATE_TABLE_AS_SELECT.md) (from v3.0 onwards)
* [INSERT](/documents/4.2/sql-reference/sql-statements/loading_unloading/INSERT.md) (from v3.0 onwards)
* [CACHE SELECT](/documents/4.2/data_source/data_cache/block_cache_warmup.md) (from v3.3 onwards)

You can view the list of tasks by querying `INFORMATION_SCHEMA.tasks`, or view the execution history of tasks by querying `INFORMATION_SCHEMA.task_runs`. For more information, see [Usage Notes](#usage-notes).

You can modify an asynchronous task using [ALTER TASK](/documents/4.2/sql-reference/sql-statements/loading_unloading/ETL/ALTER_TASK.md), or drop an asynchronous task using [DROP TASK](/documents/4.2/sql-reference/sql-statements/loading_unloading/ETL/DROP_TASK.md).

## Syntax

```SQL theme={null}
SUBMIT TASK <task_name> 
[SCHEDULE [START(<schedule_start>)] EVERY(INTERVAL <schedule_interval>) ]
[PROPERTIES(<"key" = "value"[, ...]>)]
AS <etl_statement>
```

## PROPERTIES

You can add the `session.` prefix before session variables to change the task running context configurations.

| **Property** | **Type** | **Description** |
| - | - | - |
| `session.query_timeout` | Integer | The timeout duration of a query. Unit: Seconds. Value range: 1 to 259200. Default: `300`. From v3.4.0 onwards, this variable does not apply to INSERT operations. |
| `session.insert_timeout` | Integer | The timeout duration of an INSERT operation. Unit: Seconds. Default: `14400`. Supported from v3.4.0 onwards. |
| `session.enable_profile` | Boolean | Whether to enable query profiling for the task. Default: `false`. |
| `session.new_planner_optimize_timeout` | Integer | The timeout duration of the query optimizer. Unit: Milliseconds. Default: `3000`. |

**Tip**

You can set the `warehouse` property in the statement to specify the warehouse used for this operation. By default, `default_warehouse` is used.

For example, the following statement submits a task named `test_task` with session properties which enables query profile and increase query timeout:

```SQL theme={null}
SUBMIT TASK test_task
PROPERTIES (
    "session.enable_profile" = "true",
    "session.insert_timeout" = "10000"
)
AS insert into t2 select * from t1;
```

## Parameters

| **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. The database currently supports submitting asynchronous tasks for [CREATE TABLE AS SELECT](/documents/4.2/sql-reference/sql-statements/table_bucket_part_index/CREATE_TABLE_AS_SELECT.md) and [INSERT](/documents/4.2/sql-reference/sql-statements/loading_unloading/INSERT.md). |

## Return value

* `TaskName`: The name of the task.
* `Status`: The status of the task. Valid values:
  * `SUBMITTED`: The task has been submitted.
  * `REJECTED`: The task has been rejected.
  * `FAILED`: The task has failed.

## Usage notes

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 [`tasks` in Information Schema](/documents/4.2/sql-reference/information_schema/tasks).

```SQL theme={null}
SELECT * FROM INFORMATION_SCHEMA.tasks;
SELECT * FROM information_schema.tasks WHERE task_name = '<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 [`task_runs` in Information Schema](/documents/4.2/sql-reference/information_schema/task_runs).

```SQL theme={null}
SELECT * FROM INFORMATION_SCHEMA.task_runs;
SELECT * FROM information_schema.task_runs WHERE task_name = '<task_name>';
```

## Configure via FE configuration items

You can configure asynchronous ETL tasks using the following FE configuration items:

| **Parameter** | **Default value** | **Description** |
| - | - | - |
| task\_ttl\_second | 86400 | The period during which a Task is valid. Unit: seconds. Tasks that exceed the validity period are deleted. Here, a Task indicates a non-periodic task that is performed only once. |
| task\_check\_interval\_second | 3600 | The time interval to delete invalid Tasks. Unit: seconds. |
| task\_runs\_ttl\_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. A `TaskRun` is an individual run of a periodic task. |
| task\_runs\_concurrency | 4 | The maximum number of TaskRuns that can be run in parallel. |
| task\_runs\_dispatch\_interval\_ms | 1000 | Interval at which the Leader FE checks running TaskRuns and dispatches pending ones. Unit: milliseconds. Mutable without FE restart. The new interval takes effect after the current dispatch cycle finishes. |
| task\_runs\_queue\_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. |
| task\_runs\_max\_history\_number | 10000 | The maximum number of TaskRun records to retain. |
| task\_min\_schedule\_interval\_s | 10 | The minimum interval for Task execution. Unit: seconds. |

## Examples

Example 1: Submit an asynchronous task for `CREATE TABLE tbl1 AS SELECT * FROM src_tbl`, and specify the task name as `etl0`:

```SQL theme={null}
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 theme={null}
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 theme={null}
SUBMIT TASK AS INSERT OVERWRITE tbl3 SELECT * FROM src_tbl;
```

Example 4: Submit an asynchronous task for `INSERT OVERWRITE insert_wiki_edit SELECT * FROM source_wiki_edit` without specifying the task name, and extend the query timeout to `100000` seconds using the hint:

```SQL theme={null}
SUBMIT /*+set_var(insert_timeout=100000)*/ TASK AS
INSERT OVERWRITE insert_wiki_edit
SELECT * FROM source_wiki_edit;
```

Example 5: Create an asynchronous task for an INSERT OVERWRITE statement. The task will be regularly executed at an interval of 1 minute.

```SQL theme={null}
SUBMIT TASK
SCHEDULE EVERY(INTERVAL 1 MINUTE)
AS
INSERT OVERWRITE insert_wiki_edit
    SELECT dt, user_id, count(*) 
    FROM source_wiki_edit 
    GROUP BY dt, user_id;
```

Example 6: Create a task with custom session properties:

```SQL theme={null}
SUBMIT TASK test_task
PROPERTIES (
    "session.enable_profile" = "true",
    "session.insert_timeout" = "10000"
)
AS insert into t2 select * from t1;
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.