Data Evolution: Column-level updates

Updated at:

Data Evolution is a column-level update feature in MaxCompute for Append Delta Tables. In scenarios such as large-scale column-level updates, you can use the UPDATE ... EVOLVE COLUMNS statement to update only specific columns. The data for the updated columns is written to separate files and automatically merged with the original data at read time. This approach avoids the I/O overhead caused by rewriting entire data files.

Overview

A standard UPDATE statement on an Append Delta Table rewrites the entire data files that contain matching rows. In contrast, Data Evolution writes column-level updates to separate data files. At read time, the system merges these column files with the original data row by row. This significantly reduces data overhead in write operations, especially in data pipelines that frequently add new columns or backfill values into new columns for historical data.

Use cases

  • Backfill columns after adding them

    After you add new columns by using ALTER TABLE ADD COLUMNS, you can use EVOLVE COLUMNS to backfill values for these new columns in historical rows. Unmatched rows remain NULL. This process avoids rewriting the table's entire data files.

  • Feature engineering and feature column evolution

    Feature tables often require the frequent addition of new feature columns. During model iteration, you can repeatedly adjust the values of a few feature columns and write only the data for the adjusted columns.

  • Iteratively calculate derived columns

    Derived columns, such as label or summary columns, are calculated from other columns in the same table. You can reference existing columns from the target table in the SET clause to recompute these fields in place.

  • Perform frequent column-level updates

    When you update only a few columns in a wide table, this feature avoids the write amplification and storage overhead of rewriting entire files.

Limitations

  • The UPDATE ... EVOLVE COLUMNS statement is available only for tables with the data.evolution.enable property enabled. The statement fails if this property is disabled.

  • Tables with Data Evolution enabled do not support Time Travel queries.

  • You cannot create a table with both Data Evolution enabled and a CLUSTERED BY clause.

  • When you run EVOLVE COLUMNS on a partitioned table, you must specify a partition filtering condition in the WHERE clause. Otherwise, MaxCompute blocks the job to prevent a full-partition scan.

  • Only rows that match the WHERE clause or the join condition are updated. All other rows retain their original values.

  • If you run EVOLVE COLUMNS on the same column multiple times, the latest update overwrites the previous ones.

Syntax

UPDATE <table_name> [[AS] <alias>] EVOLVE COLUMNS
SET <col1_name> = <value1> [, <col2_name> = <value2> ...]
[FROM <source_table> [[AS] <source_alias>]]
[WHERE <where_condition>];
  • The table must have the 'table.format.version'='2' and 'data.evolution.enable'='true' properties set. This feature is also supported for a partitioned table.

  • EVOLVE COLUMNS must be placed after the target table and its alias, and before the SET clause.

  • The SET clause supports assignments that use constants, columns from the source table, or expressions. Expressions can reference other columns from the target table.

Parameters

Parameter

Required

Description

table_name

Required

The name of the target table to be updated. The table must have the 'table.format.version'='2' and 'data.evolution.enable'='true' properties set.

alias

Optional

The alias for the target table. You can use <alias>.<col_name> to reference columns of the target table in the SET clause.

col1_name, col2_name

Required

The names of the columns to update. You must specify at least one column.

value1, value2

Required

The new values for the columns. A value can be a constant, a column from the source table, or an expression. An expression can reference other columns in the target table.

source_table

Optional

The source table specified in the FROM clause.

  • If a source table is provided, the statement matches rows in the target table based on the join condition.

  • If no source table is provided, the statement updates rows based on the conditions on the target table.

source_alias

Optional

The alias for the source table.

where_condition

Optional

Filters rows based on a specified condition. If this clause is omitted, all rows are updated. For a partitioned table, this clause must include a partition filtering condition.

Each UPDATE ... EVOLVE COLUMNS statement consumes computing resources and incurs costs. We recommend that you perform updates in batches to avoid submitting a large number of jobs that update only a single row.

Procedure

Step 1: Create a table and enable Data Evolution

When you create an Append Table, set 'data.evolution.enable'='true' in the TBLPROPERTIES clause. The syntax is the same for a partitioned table, but you must also add a PARTITIONED BY clause.

CREATE TABLE user_events (
    id  BIGINT,
    v1  STRING,
    v2  STRING
) TBLPROPERTIES ('table.format.version'='2', 'data.evolution.enable'='true');

Step 2: Backfill a new column after adding it

After you add a new column, use the statement without a FROM clause to backfill data based on conditions on the target table.

ALTER TABLE user_events ADD COLUMNS (v3 STRING);

UPDATE user_events AS t EVOLVE COLUMNS
SET t.v3 = 'backfill_v3'
WHERE t.id IN (1, 2);

Step 3: Update the table by joining a source table

When you include a FROM clause, the statement matches rows based on the join condition and writes values from the source table to the target columns.

UPDATE user_events AS t EVOLVE COLUMNS
SET t.v1 = s.v1
FROM user_events_src AS s
WHERE t.id = s.id;

Complete example

-- Step 1: Create an Append Table with Data Evolution enabled.
CREATE TABLE user_events (
    id  BIGINT,
    v1  STRING,
    v2  STRING
) TBLPROPERTIES ('table.format.version'='2', 'data.evolution.enable'='true');

-- Step 2: Insert base data.
INSERT INTO user_events (id, v1, v2) VALUES (1, 'a1', 'b1'), (2, 'a2', 'b2'), (3, 'a3', 'b3');

-- Step 3: Add a new column and backfill data for some rows.
ALTER TABLE user_events ADD COLUMNS (v3 STRING);

UPDATE user_events AS t EVOLVE COLUMNS
SET t.v3 = 'backfill_v3'
WHERE t.id IN (1, 2);

-- Step 4: Update column v1 by joining a source table.
CREATE TABLE user_events_src (id BIGINT, v1 STRING);
INSERT INTO user_events_src VALUES (2, 'a2_new'), (3, 'a3_new');

UPDATE user_events AS t EVOLVE COLUMNS
SET t.v1 = s.v1
FROM user_events_src AS s
WHERE t.id = s.id;

-- Step 5: Query the data to verify the results.
SELECT id, v1, v2, v3 FROM user_events ORDER BY id;

The command returns the following result:

+----+--------+----+-------------+
| id | v1     | v2 | v3          |
+----+--------+----+-------------+
| 1  | a1     | b1 | backfill_v3 |
| 2  | a2_new | b2 | backfill_v3 |
| 3  | a3_new | b3 | NULL        |
+----+--------+----+-------------+

The row with id=3 did not match the backfill condition, so its new v3 column is NULL. The value of v1 for this row was updated in Step 4 with the value from the source table.