Add additional columns
When you create a data synchronization or migration task in Data Transmission Service (DTS), you can add extra columns to the destination table and assign values to them. After data lands in the destination, filter by those column values to perform metadata management, deduplication, and sorting.
Supported scenarios
Additional columns are supported in the following source-to-destination combinations:
Source database type | Destination database type |
Any | DataHub, Lindorm, Kafka, or ClickHouse |
DB2 for LUW or DB2 for iSeries (AS/400) | MySQL or PolarDB for MySQL |
MySQL, MariaDB, or PolarDB for MySQL | MySQL, MariaDB, or PolarDB for MySQL |
MySQL | Tair/Redis, AnalyticDB for PostgreSQL, or AnalyticDB for MySQL 3.0 |
PolarDB for PostgreSQL | AnalyticDB for PostgreSQL |
SQL Server | MySQL |
Usage notes
For synchronization instances, set Synchronization Types to Schema Synchronization. For migration instances, set Migration Types to Schema Migration.
Before modifying additional column rules on a running synchronization task, check whether the column names conflict with existing columns in the destination table.
If the source database is MongoDB, the destination collections cannot contain fields named _id or _value. Otherwise, the synchronization fails.
Right-clicking a database in Selected Objects applies the configured additional columns to all tables in that destination database.
If extract, transform, and load (ETL) is configured on the synchronization task, the additional column rules run first to generate a value, and then the ETL script computes the final value that is synchronized to the destination.
Add additional columns to a synchronization task
The following steps use a synchronization instance as an example. The same approach applies to migration instances.
Prerequisites
Before you begin, ensure that you have:
A DTS synchronization or migration instance in a supported scenario
Access to the Data Management (DMS) console or the DTS console
Configure additional columns
Go to the Data Synchronization Tasks page.
Log on to the Data Management (DMS) console.
In the top navigation bar, click Data + AI.
In the left-side navigation pane, choose DTS (DTS) > Data Synchronization.
The navigation path may vary based on the DMS console mode. For details, see Simple mode console and Customize the layout and style of the DMS console. You can also go directly to the Data Synchronization Tasks page of the new DTS console.
Click Create Task and configure the source and destination databases.
To add additional columns to a Running synchronization instance, click Reselect Objects instead.
Follow the prompts to the Configure Objects step.
Set Synchronization Types to Schema Synchronization.
In Source Objects, select the databases or tables to synchronize, then click
to move them to Selected Objects.In Selected Objects, right-click the database or table.
In the dialog box, go to the Additional Columns section and click Add Column.
Enter the Column Name, Type, and Assign Value for the new column.
Column Name and Type define the column added to the destination table.
Assign Value is an expression that references source table columns or built-in variables. Click the
icon to open the expression editor. For syntax details, see Expression reference.
Click OK.
Follow the prompts to complete the rest of the task configuration.
Expression reference
An additional column value is built from constants, variables, operators, and expression functions. The syntax is compatible with the data processing DSL (Domain-Specific Language) used for ETL.
In expressions, enclose column names in backticks (`col`), not single quotation marks ('col').
Common use cases
Before diving into the full reference, here are the most common patterns:
Goal | Expression pattern |
Tag each row with its source table name |
|
Tag each row with its source database name |
|
Record the operation type (insert/update/delete) |
|
Record when the transaction was committed |
|
Build a composite key from source columns |
|
Flag inserts vs. other operations |
|
Mask sensitive data in a column |
|
Constants
Type | Example |
int |
|
float |
|
string |
|
boolean |
|
datetime |
|
Variables
Use these built-in variables to capture metadata about each replicated row.
Variable | Description | Data type | Example value |
| Name of the source table | string |
|
| Name of the source database | string |
|
| Type of DML operation | string |
|
| Time when the transaction was committed | datetime |
|
| Value of a source column for the current row | string |
|
| System Change Number (SCN) — uniquely identifies the version and time of a transaction commit | string |
|
| Address ID of a data record — uniquely locates the row. Not supported for MySQL sources. | string |
|
Expression functions
Numerical operations
Function | Syntax | Parameters | Return value | Example |
Addition |
|
| Integer if both inputs are integers; float otherwise |
|
Subtraction |
|
| Integer if both inputs are integers; float otherwise |
|
Multiplication |
|
| Integer if both inputs are integers; float otherwise |
|
Division |
|
| Integer if both inputs are integers; float otherwise |
|
Modulo |
|
| Integer if both inputs are integers; float otherwise |
|
Logical operations
Function | Syntax | Parameters | Return value | Example |
Equals |
| integer, float, or string | boolean |
|
Greater than |
| integer, float, or string | boolean |
|
Less than |
| integer, float, or string | boolean |
|
Greater than or equal to |
| integer, float, or string | boolean |
|
Less than or equal to |
| integer, float, or string | boolean |
|
AND |
| boolean | boolean |
|
OR |
| boolean | boolean |
|
IN |
|
| boolean |
|
Is null |
| any type | boolean |
|
Is not null |
| any type | boolean |
|
String functions
Function | Syntax | Parameters | Return value | Example |
Concatenate strings |
| strings | Concatenated string |
|
Format and concatenate |
|
| Formatted string |
|
Replace substring |
|
| String after replacement |
|
Replace in all string fields |
|
| String after replacement |
|
Strip characters |
|
| String with leading/trailing characters removed |
|
Convert to lowercase |
| string column or constant | Lowercase string |
|
Convert to uppercase |
| string column or constant | Uppercase string |
|
String to integer |
| string | Integer |
|
Integer to string |
| integer | String |
|
Count occurrences |
|
| Number of occurrences |
|
Find substring |
|
| Position of first match; |
|
Check if all letters |
| string column or constant | boolean |
|
Check if all digits |
| string column or constant | boolean |
|
Regular expression match |
|
| boolean |
|
Mask part of a string |
|
| Masked string |
|
Get substring after a string |
|
| Substring after |
|
Get substring before a string |
|
| Substring before |
|
Get substring between two strings |
|
| Substring between |
|
Check if value is a string |
| string or column name | boolean |
|
Get a field from a MongoDB document |
| Nested field path | Field value |
|
Conditional expressions
Syntax | Parameters | Return value | Example |
|
|
|
|
Time functions
Function | Syntax | Parameters | Return value | Example |
Current time (second precision) |
| None | DATETIME, accurate to the second |
|
Current time (millisecond precision) |
| None | DATETIME, accurate to the millisecond |
|
UTC timestamp (seconds) to DATETIME |
|
| DATETIME, accurate to the second |
|
UTC timestamp (milliseconds) to DATETIME |
|
| DATETIME, accurate to the millisecond |
|
DATETIME to UTC timestamp (seconds) |
|
| Integer |
|
DATETIME to UTC timestamp (milliseconds) |
|
| Integer |
|
DATETIME to string |
|
| String |
|
String to DATETIME |
|
| DATETIME |
|
Adjust DATETIME |
|
| DATETIME |
|
Global functions
Flow control functions
Function
Syntax
Parameters
Example
if statement
e_if(bool_expr, func_invoke)
bool_expr: boolean constant or function call. Constants: true or false. Function call example: op_gt(`id`, 10).
func_invoke: function call. Supported: e_drop, e_keep, e_set, e_if, e_compose
e_if(op_gt(`id`, 10), e_drop()); drops the record if ID > 10.
if-else statement
e_if_else(bool_expr, func_invoke1, func_invoke2)
bool_expr: boolean constant or function call. Constants: true or false. Function call example: op_gt(`id`, 10).
func_invoke1: function call executed if condition is true.
func_invoke2: function call executed if condition is false.
e_if_else(op_gt(`id`, 10), e_set(`tag`, 'large'), e_set(`tag`, 'small')); sets tag to "large" if ID > 10, otherwise to "small".
Switch-like statement that evaluates multiple conditions and executes the first matching operation. Executes a default operation if no conditions match.
s_switch(condition1, func1, condition2, func2, ..., default=default_func)
condition1: boolean constant or function call. Constants: true or false. Function call example: op_gt(`id`, 10).
func_invoke: function call. Checks condition1; if true, executes this function and exits the switch. If false, checks the next condition.
default_func: function call executed if all conditions are false.
e_switch(op_gt(`id`, 100), e_set(`str_col`, '>100'), op_gt(`id`, 90), e_set(`str_col`, '>90'), default=e_set(`str_col`, '<=90')).
Combine multiple operations
e_compose(func1, func2, func3, ...)
func1: function call. Can be e_set, e_drop, e_if.
func2: function call. Can be e_set, e_drop, e_if.
e_compose(e_set(`str_col`, 'test'), e_set(`dt_col`, dt_now())); sets str_col to "test" and dt_col to the current time.
Data manipulation functions
Function
Syntax
Parameters
Example
Drop this record (do not synchronize)
e_drop()
None
e_if(op_gt(`id`, 10), e_drop()); drops records where ID > 10.
Keep this record (synchronize to destination)
e_keep(condition)
condition: boolean expression
e_keep(op_gt(id, 1)); synchronizes only records where ID > 1.
Set column value
e_set(`col`, val, NEW)
col: column name
val: constant or function call. Must match col's data type.
NEW: converts col to val's data type (optional)
ImportantIf you omit NEW, do not include the preceding comma. Ensure data type compatibility to avoid task errors.
e_set(`dt_col`, dt_now()); sets dt_col to current time.
e_set(`col1`, `col2` + 1); sets col1 to col2 + 1.
e_set(`col1`, 1, NEW); converts col1 to numeric type and sets it to 1.
MongoDB field retention, field dropping, and field name mapping
e_expand_bson_value('*', 'fieldA',{"fieldB":"fieldC"})
*: field names to retain; * means all fields.
fieldA: field names to drop.
{"fieldB":"fieldC"}: field name mapping; fieldB is the source field name, fieldC is the destination field name.
NoteField name mapping is optional.
e_expand_bson_value("*", "_id,name"); writes all fields except _id and name to the destination.
FAQ
How do I configure custom keys and values for a DTS task from MySQL to Redis?
By default, DTS maps the entire source row using one of three Cache Mapping Mode options. To extract specific columns and build custom key-value pairs instead, add two special additional columns: __DTS_TP_TO_REDIS_KEY__ and __DTS_TP_TO_REDIS_VALUE__.
The three cache data mapping modes are as follows:
KV Model (Database-Table-Primary Key)
HASH Model (Database-Table-Primary Key)
HASH Model (Database-Table)
You also need to configure the Value Data Splitting Method (options: JSON format, Key-Value comma-separated, or Value comma-separated), and select the DML operation types to synchronize (INSERT, UPDATE, DELETE).
Configuration steps:
When configuring objects, move the databases and tables to the right pane, then click the edit button for the destination Redis DB.
Add the columns
__DTS_TP_TO_REDIS_KEY__and__DTS_TP_TO_REDIS_VALUE__.Set the Assign Value expressions using DSL syntax. For example, consider the following MySQL
aestable:CREATE TABLE `aes` ( `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'Auto-increment primary key', `login_time` INT(10) NOT NULL DEFAULT '0' COMMENT 'Logon identifier time', `pay_time` INT(10) NOT NULL DEFAULT '0' COMMENT 'Payment identifier time', `gid` INT(10) NOT NULL DEFAULT '0' COMMENT 'Game ID', `cid` INT(10) NOT NULL DEFAULT '0' COMMENT 'Channel ID', `gcp_code` VARCHAR(40) NOT NULL DEFAULT '' COMMENT 'Channel package number. An empty value indicates a new entry for the gid.', `uname` VARCHAR(120) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '' COMMENT 'Account', PRIMARY KEY (`id`), UNIQUE KEY `idx_uq` (`gid`, `gcp_code`, `uname`), KEY `idx_uname` (`uname`) )ENGINE=InnoDB AUTO_INCREMENT=48022 DEFAULT CHARSET=utf8 COMMENT='Game account activation time information table';Business requirements:
Key:
stat_create_day:{gcp_code}:{uname}— built from two source columnsValue:
{login_time}— a Unix timestamp converted to datetime format
Assign Value expressions:
__DTS_TP_TO_REDIS_KEY__:'stat_create_day'+':'+gcp_code+':'+uname__DTS_TP_TO_REDIS_VALUE__:dt_fromtimestamp(cast_string_to_long(login_time))
After synchronization or migration completes, the key-value pair in Redis appears as follows:
After data synchronization is complete, connect to the target Redis instance through DMS. In DB0, run the
getcommand on keys of thestat_create_day:{gcp_code}:{uname}type. The returned value is in datetime format (for example,2025-11-18 23:49:29), which confirms that thedt_fromtimestampfunction has correctly converted the Unix timestamp to a datetime value.