MaxCompute asynchronous generated columns guide
Asynchronous generated columns support computing and storing the values of derived fields asynchronously through an associated task after source data is written. Queries read the stored results directly. This feature suits scenarios such as text vectorization, where computation is expensive and results can be ready a little later. This topic describes how asynchronous generated columns work, how to use them, and related precautions.
Asynchronous generated columns store the compute expression of a derived field in the table schema. After source data is written, the system computes and stores the values of the generated column through an associated task, and queries read the stored results directly. This feature suits scenarios such as text vectorization, where computation is expensive and results can be ready a little later.
The asynchronous generated column of a newly written record may first appear as NULL, and the result can be read only after the associated task finishes processing. Before using the data, downstream tasks must check whether the target batch has been processed.
Periodic tasks are currently in invitational preview. This topic applies only to projects where asynchronous generated columns and periodic tasks are enabled. The actual availability is subject to the target public cloud version.
Usage limits
Item | Requirement |
Table type | MaxCompute-managed Append Delta Table without a primary key |
Table format |
|
Transaction property |
|
Data Evolution |
|
Number of columns | At most one asynchronous generated column per table. Synchronous generated columns can coexist. |
CDC | Cannot be enabled at the same time as |
NOT NULL constraint | Data columns cannot be declared as |
Partitions | Partitioned tables are supported, but an asynchronous generated column cannot be used as a partition column, and the expression cannot reference partition columns. |
Other table types | Not applicable to regular non-Delta tables, external tables, or Object Tables. |
The execution account must have permissions to create and alter tables, write and query data, and view and manage periodic tasks. When a model is used, the corresponding model invocation permissions are also required. Background computing and model invocation may incur fees. Check the billing documentation of MaxCompute and the model service before execution.
The examples in this topic demonstrate only INSERT INTO append writes.
Quick start
The following example uses TOUPPER to convert strings to uppercase. The example does not depend on an external model.
The following SQL statements are executed in order in the same session by default. If they are submitted as separate jobs, add the required SET statements to the jobs that need them.
Step 1: Create a table
SET odps.sql.type.system.odps2=true;
SET odps.table.append2.enable=true;
CREATE TABLE async_text_demo (
id STRING,
content STRING,
normalized_content STRING
GENERATED ALWAYS AS (TOUPPER(content)) STORED ASYNC
)
TBLPROPERTIES (
'transactional'='true',
'table.format.version'='2',
'data.evolution.enable'='true'
);
After the table is created, the system creates an associated task. No additional compute SQL or scheduling task needs to be written.
Step 2: Write source data
INSERT INTO async_text_demo (id, content)
VALUES ('1', 'hello'), ('2', 'maxcompute');
When writing data, provide only the regular columns. Do not assign a value to normalized_content or add a NULL placeholder.
Step 3: Query the generated column
SELECT id, content, normalized_content
FROM async_text_demo
ORDER BY id;
Before the task finishes processing, normalized_content may be NULL. After processing is complete, this example should return HELLO and MAXCOMPUTE. If the task has already finished before the query, the first query returns the final result.
Step 4: Check the table definition and associated task
SHOW CREATE TABLE async_text_demo;
SET odps.sql.periodic.task.enabled=true;
SHOW TASKS;
DESC TASK periodic_task_async_text_demo_normalized_content;
SHOW HISTORY FOR TASK periodic_task_async_text_demo_normalized_content
LIMIT 10 OFFSET 0;
SHOW CREATE TABLE is used to check the generated column expression. The task name may be affected by the project, schema, and table name. Confirm the actual name by using SHOW TASKS, and then run the subsequent task management commands.
Add an asynchronous generated column to an existing table
If an existing table meets the usage limits and does not yet have an asynchronous generated column, run the following statement:
ALTER TABLE existing_texts ADD COLUMNS (
normalized_content STRING
GENERATED ALWAYS AS (TOUPPER(content)) STORED ASYNC
);
Replace existing_texts and content with the actual table name and regular column name. After the column is added, the system creates an associated task.
After the DDL statement is executed successfully, check the processing status of the target data through the task history and result queries. When operating on an existing table, first verify the backfill scope of historical data in the target version. If the business requires a full recalculation of historical data, create a new table and reimport the source data.
Expression requirements
The expression can reference regular data columns of the current table but cannot reference other generated columns.
Scalar expressions and deterministic built-in scalar functions that meet the type requirements are supported, such as
TOUPPER, arithmetic operations,CASE WHEN, and type conversion.Asynchronous generated columns support
AI_EMBEDDING, but the model, return type, and dimension requirements must still be met.Aggregate functions, window functions, cross-table subqueries, custom UDFs, and UDT methods are not supported.
The declared type of the generated column must match the expression result. If conversion is required, use
CASTexplicitly.Do not specify
DEFAULTfor a generated column.ASYNCmust be written afterSTORED.
Verify the expression with a regular SELECT before using it for a generated column. For example, a string column cannot accept an ARRAY<DOUBLE> result, and RAND() does not become a usable expression just because ASYNC is used.
Query and check results
To read only existing computed results, filter out nulls:
SELECT id, normalized_content
FROM async_text_demo
WHERE normalized_content IS NOT NULL;
To check result coverage, run the following statement:
SELECT
COUNT(*) AS total_rows,
COUNT(normalized_content) AS non_null_results,
COUNT(*) - COUNT(normalized_content) AS null_results
FROM async_text_demo;
The number of null values is not equal to the number of pending records. An expression may legitimately return NULL, and records that failed processing also appear as nulls. Therefore, also check the source data, task history, and execution instances.
For the uppercase conversion example in this topic, check whether source values and derived values are consistent:
SELECT id, content, normalized_content
FROM async_text_demo
WHERE content IS NOT NULL
AND (
normalized_content IS NULL
OR normalized_content <> TOUPPER(content)
);
Run the preceding query only after confirming that the task instances covering the target batch have all succeeded. If records are still returned, check whether unprocessed or failed batches exist. Do not assume that all data is ready based only on the latest successful task run.
Generate text vectors
Before execution, complete model preparation and permission configuration by referring to the AI_EMBEDDING document, and confirm that the current project supports the corresponding model invocation.
The following example uses the public model bigdata_public_modelset.default.`text-embedding-v4`. If the target project cannot use this model, replace it with a model that has already been authorized, and use the full model reference.
Step 1: Verify the model invocation
SET odps.namespace.schema=true;
SET odps.sql.type.vector.enable=true;
SET odps.sql.ai.embedding.dimension=1024;
SELECT AI_EMBEDDING(
bigdata_public_modelset.default.`text-embedding-v4`,
DEFAULT_VERSION,
'MaxCompute supports asynchronous generated columns.'
) AS embedding;
Confirm that the function can be executed, and check the return type and dimension. The declared type of the generated column must match the actual return type of the function.
Step 2: Create a table and write text
When creating the table, set odps.sql.periodic.task.enabled to True.
SET odps.namespace.schema=true;
SET odps.sql.type.system.odps2=true;
SET odps.table.append2.enable=true;
SET odps.sql.type.vector.enable=true;
SET odps.sql.ai.embedding.dimension=1024;
SET odps.sql.periodic.task.enabled=true;
CREATE TABLE async_documents (
doc_id STRING,
content STRING,
embedding VECTOR(FLOAT, 1024)
GENERATED ALWAYS AS (
AI_EMBEDDING(
bigdata_public_modelset.default.`text-embedding-v4`,
DEFAULT_VERSION,
content
)
) STORED ASYNC
)
TBLPROPERTIES (
'transactional'='true',
'table.format.version'='2',
'data.evolution.enable'='true'
);
INSERT INTO async_documents (doc_id, content)
VALUES ('doc_001', 'MaxCompute supports asynchronous generated columns.');
Step 3: Query vector results
SELECT doc_id, embedding
FROM async_documents
WHERE embedding IS NOT NULL;
The value 1024 in the example must be consistent with the model output and the column declaration. DEFAULT_VERSION uses the default version of the model. If the business needs to maintain the same vector semantics over the long term, use a manageable fixed model version, and plan model upgrades and historical data recalculation separately.
After the task is created, check the actual configuration by using SHOW CREATE TASK. If the model or dimension needs to be adjusted, confirm whether the adjustment applies to the existing task, and do not modify only the SET configuration in the query session.
After vectors are generated, a vector index still needs to be created separately. When the default model version is changed, do not assume that the system automatically recalculates all historical data.
Manage associated tasks
View status and history
SET odps.sql.periodic.task.enabled=true;
SHOW TASKS;
DESC TASK periodic_task_async_text_demo_normalized_content;
SHOW HISTORY FOR TASK periodic_task_async_text_demo_normalized_content
LIMIT 10 OFFSET 0;
DESC TASK is used to view the task status, status reason, scheduling configuration, and task content. The actual scheduling configuration is subject to the result returned by this command. The scheduling interval is not the data completion time limit. Resource queuing, scanning, model invocation, and result submission all affect when data is ready.
Task history includes instanceId, creation time, end time, and status. When there is no new data, the task may skip actual computation. Therefore, a successful record does not mean that new records were processed in this run.
View logs of failed instances
Obtain the target instanceId from the task history, and run the following statement:
WAIT <instanceId>;After the command returns a LogView URL, view the detailed logs in a browser. Alternatively, view the instance in the Periodic Task details page in the MaxCompute console.
Suspend and resume tasks
To suspend subsequent scheduling:
ALTER TASK periodic_task_async_text_demo_normalized_content SUSPEND;
After maintenance is complete, resume the task:
ALTER TASK periodic_task_async_text_demo_normalized_content RESUME;
Suspending a task does not cancel running instances. After the task is resumed, check the task history and the results of the target batch again. If the task is in the suspended state, first view the reason by using DESC TASK, and then handle failed instances.
Task management commands must be submitted one at a time. ALTER TASK does not support Script Submit Mode.
Adjust the scheduling interval
ALTER TASK periodic_task_async_text_demo_normalized_content
SET SCHEDULE = '5 minutes';After the adjustment, check the configuration by using DESC TASK. A longer scheduling interval increases data waiting time, and a shorter interval cannot eliminate resource queuing and computation time.
Modify the table structure or disable the feature
Operation | Description |
Create a table and define an asynchronous generated column | Supported. The system automatically creates an associated task. |
Run | Supported. The system automatically creates an associated task. |
| Not supported. Create the table first, and then run |
Add a second asynchronous generated column to a table | Not supported |
Change a regular column to an asynchronous generated column or directly modify the generated column definition | Cannot be done by using |
Drop, rename, or change the type of a referenced source column | Constrained by the generated column dependency. Handle the generated column first. |
Use | Not supported |
Drop an asynchronous generated column | The associated task is also cleaned up. |
Drop a table | The associated task is also deleted. |
For temporary maintenance, use ALTER TASK ... SUSPEND instead of dropping the generated column. To disable the feature and delete the results, run the following statement:
ALTER TABLE async_text_demo DROP COLUMN normalized_content;
Do not delete the associated task created by the system separately, and do not directly rely on table renaming to migrate tasks automatically. If the table name or generation logic needs to be changed, create a new table, complete data migration and result verification, and then switch downstream tasks.
FAQ
Symptom | Solution |
The message " | Check the table type, and create an Append Delta Table without a primary key according to the usage limits |
The message indicates that | Check the table structure constraints, and enable Data Evolution after the conditions are met |
The message indicates that only one asynchronous generated column is allowed | Split different processing results into different tables or separate processing pipelines |
The message indicates that asynchronous generated columns and CDC cannot be enabled at the same time | Adjust the table usage to avoid combining them in the same table |
Expression function or type validation fails | Verify the expression with a regular |
The message indicates that the generated column is not writable during insertion | Write only regular columns. Do not assign values to generated columns or add placeholder fields |
The generated column remains | Check the task status, target batch history, failed instances, and source data |
The task is suspended | Use |
| View the logs based on |
Historical vectors do not change after a model upgrade | Do not rely on a model upgrade to trigger a full recalculation. Recalculate by using a new table, and migrate the data |