This feature is in invitational preview. For details on accessing features in invitational preview, see Instructions.
Without a built-in scheduler, recurring data pipelines require external orchestration tools — adding cost and operational overhead. MaxCompute periodic tasks let you define and run SQL-based data pipelines on a recurring schedule, from every 10 seconds to every 59 minutes, using only SQL statements. No external scheduler is required.
Workflow overview
A typical end-to-end workflow:
-
Enable periodic tasks for the session by setting
odps.sql.periodic.task.enabled=true. -
Create supporting objects — Delta Tables and streams — if your task reads from a stream.
-
Create the task with
CREATE TASK, specifying the schedule, optionalWHENcondition, and retry strategy. -
Verify the task is ACTIVE using
DESC TASK. -
Monitor execution history with
SHOW HISTORY FOR TASK. -
Modify, suspend, or delete the task as needed with
ALTER TASKorDROP TASK.
How it works
Each periodic task runs a SQL statement on a fixed interval. Before each execution, the task evaluates an optional WHEN condition. If the condition returns FALSE, that execution is skipped — the task does not run the SQL body, but remains scheduled and evaluates the condition again on the next interval.
This pattern is useful for building data pipelines that process only when new data is available. For example, use WHEN stream_has_data('my_stream') to skip executions when the stream is empty, avoiding unnecessary compute. By default, the task automatically generates incremental CDC data in the background.
Key behaviors:
-
WHENis a gate, not a trigger. The task still fires on its fixed schedule;WHENcontrols whether the SQL body runs. -
A periodic task starts automatically after creation. Its initial status is ACTIVE.
-
To suspend or resume a task, use
ALTER TASK ... suspendorALTER TASK ... resume.
Prerequisites
Before you begin, ensure that you have:
-
A MaxCompute project with the periodic task feature enabled (invitational preview)
-
Permissions to create and manage tasks in the project
-
(For console access) The
AliyunMaxComputeReadOnlyAccesspolicy granted to your RAM user. For details, see RAM permissions
Usage notes
Set the following parameter at the session level before creating or deleting periodic tasks. Without it, CREATE TASK and DROP TASK return an error.
SET odps.sql.periodic.task.enabled=true;
Create a periodic task
Syntax
CREATE TASK [IF NOT EXISTS] <task_name>
SCHEDULE = "<num> [minute|minutes] | [second|seconds]"
[TASKPROPERTIES("schedule_strategy"="<retries>",
"odps.namespace.schema"="true" ...)]
[COMMENT task_comment]
[WHEN <bool_expr>]
AS <taskBody>;
Parameters
| Parameter | Required | Description |
|---|---|---|
IF NOT EXISTS |
No | If a task with the same name already exists, the operation succeeds and the existing task is not modified. Without this option, creating a task with a duplicate name returns an error. |
task_name |
Yes | The name of the periodic task. |
SCHEDULE |
Yes | The execution interval. Supported units: second/seconds (value: 10–59) and minute/minutes. For intervals of 60 seconds or more, use minutes. Value range: 10 seconds to 3,540 seconds. |
TASKPROPERTIES |
No | Execution parameters for the SQL body. Common settings: schedule_strategy (number of retries on failure), odps.stage.reducer.num (number of Reduce Task instances), odps.sql.reducer.memory (memory per Reduce Task instance, in MB). |
COMMENT |
No | A comment for the task. Maximum length: 1,024 bytes. |
WHEN |
No | A Boolean expression evaluated before each scheduled run. The task body runs only when this expression returns TRUE. Defaults to TRUE if omitted. Supports scalar functions only — window functions, aggregate functions, and nested subqueries are not supported. For the full list of supported functions, see Function whitelist. |
AS <taskBody> |
Yes | The SQL statement to run. Supports Data Manipulation Language (DML) and Data Query Language (DQL). Data Definition Language (DDL) and SQL statements run from the code editor are not supported. |
Example: create a task with a stream condition
This example creates a task that reads new rows from a Delta Table stream and inserts them into a destination table every 5 minutes. The task body runs only when the stream has new data.
Step 1: Create the destination Delta Table.
CREATE TABLE acid2_table_dest (
pk BIGINT NOT NULL PRIMARY KEY,
val BIGINT
) tblproperties ("transactional"="true");
Step 2: Create the source Delta Table and a stream on it.
-- Source Delta Table
CREATE TABLE delta_table_src (
pk BIGINT NOT NULL PRIMARY KEY,
val BIGINT
) tblproperties ("transactional"="true");
-- Stream on the source table (append mode, starting from version 1)
CREATE STREAM delta_table_stream
ON TABLE delta_table_src version as of 1
strmproperties('read_mode'='append')
comment 'stream demo';
Step 3: Create the periodic task.
SET odps.sql.periodic.task.enabled=true;
CREATE TASK IF NOT EXISTS periodic_task1
SCHEDULE = '5 minutes'
TASKPROPERTIES('schedule_strategy'='3')
COMMENT 'task_comment'
WHEN stream_has_data('delta_table_stream')
AS INSERT INTO acid2_table_dest SELECT pk, val FROM delta_table_stream;
stream_has_data('delta_table_stream')is equivalent to runningSELECT stream_has_data('delta_table_stream');in MaxCompute. Withschedule_strategy=3, the task retries up to 3 times if a scheduled run fails.
Step 4: Insert test data and verify the result.
-- Insert test data into the source table
INSERT INTO delta_table_src VALUES (1, 1), (2, 2);
-- After the next scheduled run, query the destination table
SELECT * FROM acid2_table_dest;
Expected output:
+------------+------------+
| pk | val |
+------------+------------+
| 1 | 1 |
| 2 | 2 |
+------------+------------+
Modify a periodic task
Use ALTER TASK to update the schedule, execution properties, comment, or WHEN condition of an existing task, or to suspend and resume it.
A periodic task starts automatically after creation with status ACTIVE. To pause it, useALTER TASK ... suspend. To return it to ACTIVE status, useALTER TASK ... resume. Verify the current status withDESC TASK.
Syntax
Modify schedule, properties, or comment:
ALTER TASK [IF EXISTS] <task_name>
SET SCHEDULE = "<num> [minute|minutes] | [second|seconds]"
[TASKPROPERTIES("schedule_strategy"="<retries>", ...)]
[COMMENT task_comment];
Suspend or resume:
ALTER TASK [IF EXISTS] <task_name> resume | suspend;
Modify the WHEN condition:
ALTER TASK [IF EXISTS] <task_name> MODIFY WHEN <boolean_expr>;
Parameters
| Parameter | Required | Description |
|---|---|---|
IF EXISTS |
No | If the task does not exist, the operation is skipped and a success message is returned. Without this option, modifying a non-existent task returns an error. |
boolean_expr |
Yes (for MODIFY WHEN) |
The new Boolean expression for the task's trigger condition. |
For SCHEDULE and TASKPROPERTIES, see Parameters in the Create a periodic task section.
Common scenarios
Suspend a task, update its schedule and retry count, then resume:
ALTER TASK periodic_task1 suspend;
ALTER TASK IF EXISTS periodic_task1 SET SCHEDULE = '6 minute';
ALTER TASK IF EXISTS periodic_task1 SET TASKPROPERTIES('schedule_strategy'='5');
ALTER TASK periodic_task1 resume;
Update the WHEN condition:
ALTER TASK IF EXISTS periodic_task1 MODIFY WHEN 1=1;
Add or update a comment:
ALTER TASK IF EXISTS periodic_task1 SET COMMENT 'comment2';
Delete a periodic task
Syntax
SET odps.sql.periodic.task.enabled=true;
DROP TASK [IF EXISTS] <task_name>;
Parameters
| Parameter | Required | Description |
|---|---|---|
IF EXISTS |
No | If the task does not exist, the operation is skipped and a success message is returned. Without this option, dropping a non-existent task returns an error. |
task_name |
Yes | The name of the periodic task to delete. |
Example
SET odps.sql.periodic.task.enabled=true;
DROP TASK periodic_task1;
View task information
Use commands
View basic information:
DESC TASK <task_name>;
View extended information:
DESC EXTENDED TASK <task_name>;
Example output for DESC TASK periodic_task1:
+------------------------------------------------------------------------------------+
| Owner: ALIYUN$odps****@aliyun.com |
| Project: sql_odps2 |
| Schema: |
| Task: periodic_task1 |
+------------------------------------------------------------------------------------+
| CreateTime: 2024-08-23 11:05:46 |
| LastModifiedTime: 2024-08-23 11:05:46 |
+------------------------------------------------------------------------------------+
| ScheduleText: '5 minute' |
| TaskType: SQL |
| Query: insert into acid2_table_dest select pk, val from acid_stream; |
| Condition: stream_has_data('acid_stream') |
| Status: ACTIVE |
| Comment: |
+------------------------------------------------------------------------------------+
Use the console
-
Log on to the MaxCompute console and select a region.MaxCompute console
-
In the left navigation pane, choose Manage Configurations > Projects.
-
On the Projects page, find the target project and click Manage in the Actions column.
-
On the Project Settings page, select the Periodic Task tab to view all periodic tasks in the project.
-
Click Details in the Actions column of the target task.
-
In the View Periodic Task dialog box, review the Task Name, Task Status, Scheduling Cycle, and Execution Log.
-
Click an Instance ID to open the Job Insights page and view detailed execution logs.
List all periodic tasks
SHOW TASKS;
Example output:
+--------------------------------------------------------------------------------------------------------------------------------+
| Project: openmronlot_daily_arm_src3_xr |
| Schema: |
+--------------------------------------------------------------------------------------------------------------------------------+
| Tasks: |
+--------------------------------------------------------------------------------------------------------------------------------+
| Name | Owner | CreateTime | LastModifiedTime | Status |
+--------------------------------------------------------------------------------------------------------------------------------+
| periodic_task1 | ALIYUN$odpst****@aliyun.com | 2024-07-26 16:19:06 | 2024-07-26 16:19:06 | ACTIVE |
| periodic_task2 | ALIYUN$odpst****@aliyun.com | 2024-07-26 16:19:28 | 2024-07-26 16:19:28 | ACTIVE |
| periodic_task3 | ALIYUN$odpst****@aliyun.com | 2024-07-26 16:20:45 | 2024-07-26 16:20:45 | ACTIVE |
| periodic_task6 | ALIYUN$odpst****@aliyun.com | 2024-08-15 11:09:55 | 2024-08-15 11:09:55 | ACTIVE |
| periodic_task_alter1 | ALIYUN$odpst****@aliyun.com | 2024-07-26 16:17:40 | 2024-07-26 16:17:40 | ACTIVE |
+--------------------------------------------------------------------------------------------------------------------------------+
SHOW TASKS lists all tasks in the current project. To filter by task name, use the MaxCompute console's Periodic Task tab.
View execution history
SHOW HISTORY FOR TASK returns the InstanceId, CreateTime, EndTime, and Status of each scheduled run.
To view detailed logs for a specific run, use WAIT to get the Logview URL, then open it in a browser:
WAIT <InstanceId>;
-- Example: WAIT 2024082309000177gq71ut9****;
Syntax
SHOW HISTORY FOR TASK <task_name> [[LIMIT <limit_value>] OFFSET <offset_value>];
Parameters
| Parameter | Required | Description |
|---|---|---|
task_name |
Yes | The name of the periodic task. |
limit_value |
No | The number of records to return. Must be greater than 0. If omitted, returns as many records as possible. Example: LIMIT 50 returns 50 records. |
offset_value |
No | The number of records to skip from the latest. OFFSET 0 starts from the most recent record. |
Examples
View all history for periodic_task1:
SHOW HISTORY FOR TASK periodic_task1;
Output:
+---------------------------------------------------------------------------------------------------+
| Project: muze_demo |
| Schema: |
| Task: periodic_task1 |
+---------------------------------------------------------------------------------------------------+
| History: |
+---------------------------------------------------------------------------------------------------+
| InstanceId | CreateTime | EndTime | Status |
+---------------------------------------------------------------------------------------------------+
| 202506130710002599mhgq4**** | 2025-06-13 15:10:00 | 2025-06-13 15:10:00 | Terminated |
| 2025061307050039g47jzzs1**** | 2025-06-13 15:05:00 | 2025-06-13 15:05:00 | Terminated |
| 2025061307000030o9vh1l1**** | 2025-06-13 15:00:00 | 2025-06-13 15:00:00 | Terminated |
| 2025061306550032l84ahcr4**** | 2025-06-13 14:55:00 | 2025-06-13 14:55:00 | Terminated |
| 2025061306500043cthoc62**** | 2025-06-13 14:50:00 | 2025-06-13 14:50:00 | Terminated |
| 20250613064500324fkhaz1**** | 2025-06-13 14:45:00 | 2025-06-13 14:45:00 | Terminated |
| 2025061306400048194cx8g**** | 2025-06-13 14:40:00 | 2025-06-13 14:40:00 | Terminated |
| 20250613063500351g99kf2**** | 2025-06-13 14:35:00 | 2025-06-13 14:35:00 | Terminated |
| 2025061306300084qkbtk9**** | 2025-06-13 14:30:00 | 2025-06-13 14:30:00 | Terminated |
| 20250613062501711nswoio**** | 2025-06-13 14:25:01 | 2025-06-13 14:25:01 | Terminated |
| 2025061306200129vln5ncr4**** | 2025-06-13 14:20:01 | 2025-06-13 14:20:01 | Terminated |
| 2025061306150119yhlkmbo**** | 2025-06-13 14:15:00 | 2025-06-13 14:15:01 | Terminated |
| 2025061306100139uemvy7r6**** | 2025-06-13 14:10:00 | 2025-06-13 14:10:01 | Terminated |
+---------------------------------------------------------------------------------------------------+
View the 6 most recent runs:
SHOW HISTORY FOR TASK periodic_task1 LIMIT 6 OFFSET 0;
Skip the 5 most recent runs and view the rest:
SHOW HISTORY FOR TASK periodic_task1 OFFSET 5;
Function whitelist
The WHEN condition supports scalar functions only. Window functions, aggregate functions, and nested subqueries are not supported. The following functions are available. For details on each function, see Built-in functions (alphabetical order).
Date and time
DATEADD, DATEDIFF, DATEPART, DATETRUNC, DATE_FORMAT, FROM_UNIXTIME, GETDATE, ISDATE, LASTDAY, LAST_DAY, UNIX_TIMESTAMP, WEEKDAY, WEEKOFYEAR, TO_DATE, TO_CHAR, YEAR, QUARTER, MONTH, DAY, DAYOFMONTH, HOUR, MINUTE, SECOND, CURRENT_TIMESTAMP, FROM_UTC_TIMESTAMP, ADD_MONTHS, NEXT_DAY, MONTHS_BETWEEN, TO_MILLIS
Math
ABS, ROUND
String
CONCAT, CONCAT_WS, GET_JSON_OBJECT, INSTR, LENGTH, LENGTHB, REGEXP_EXTRACT, REGEXP_REPLACE, REGEXP_INSTR, REGEXP_SUBSTR, REGEXP_COUNT, REVERSE, SUBSTR, TOLOWER, TOUPPER, TRIM, LTRIM, RTRIM, REPLACE, SIZE, FIELD
Conditional and JSON
COALESCE, IF, SPLIT, SPLIT_PART, FROM_JSON
Table and partition
MAX_PT, TABLE_EXISTS, PARTITION_EXISTS, GET_LATEST_VERSION, GET_LATEST_TIMESTAMP, STREAM_HAS_DATA, TABLE_NEED_CDC_BUILD