The Code Editor allows you to write a JSON script for data synchronization and use DataWorks scheduling parameters to periodically synchronize full or incremental data from a single source table or sharded tables to a destination table. Configurations vary by data source. For details, see the list of data sources.
Usage notes
Use the Code Editor in the following scenarios:
-
The data source does not support configuration in wizard mode.
NoteThe user interface indicates whether a data source supports wizard mode.
For example, if you select HBase11xsql as the destination data source, a yellow warning message appears on the network and resource configuration page: "The current data source type does not support task editing in wizard mode. The task will be configured in script mode." In this case, click the Code Editor button in the toolbar to switch modes and configure the task.
-
Some data source configuration parameters are available only in the Code Editor.
-
You can use the Code Editor to configure some data sources that cannot be created directly in DataWorks.
Prerequisites
-
Make sure that the required source and destination data sources are configured in DataWorks. For more information, see Data source list.
Note-
For more information about the data sources supported by batch synchronization and their configurations, see Supported data sources and sync solutions.
-
For more information about data source features, see Data source configuration.
-
Purchase a resource group with appropriate specifications and associate it with the workspace. For more information, see Use serverless resource groups.
Establish network connectivity between the resource group and the data sources. For more information, see Configure network connectivity.
Step 1: Create a batch synchronization node
Data Studio (new version)
Log on to the DataWorks console. In the left-side navigation pane, choose . Select the desired workspace from the drop-down list and click <p><a href={url} target="_blank">Learn more.</a></p>Data Studio.
Create a workflow. For more information, see Workflows.
Create a Data Integration node in one of the following ways:
Method 1: In the upper-right corner of the workflow list, click
, and then choose .Method 2: Double-click the workflow name, and then drag the Data Integration node from the Data Integration directory to the workflow editing panel on the right.
Configure the source and destination types for the node, select Single Table Batch Sync as the specific type, and click OK to complete the creation.
Legacy Data Studio
Log on to the DataWorks console. In the left-side navigation pane, choose . Select the desired workspace from the drop-down list and click Data Analytics.
Create a workflow. For more information, see Create a workflow.
Create a batch synchronization node in one of the following ways:
Method 1: Expand the workflow, right-click .
Method 2: Double-click the workflow name, and then drag the Batch Synchronization node from the Data Integration directory to the workflow editing panel on the right.
Follow the on-screen instructions to create a batch synchronization node.
Step 2: Configure the data source and resource group
You can switch from wizard mode to script mode at any step. For a complete script configuration, we recommend the following approach:
-
First, use the wizard to select the data source and resource group, and test network connectivity.
-
Then switch to script mode.
The system automatically populates this information into the generated JSON script.
Alternatively, you can switch directly and then manually configure the settings in script mode: specify the data source in the JSON code, and set the resource group and required resource size in the Advanced Settings panel on the right.
-
If you have created a resource group but it is not displayed here, check whether the resource group has been associated with the workspace. For more information, see Create and manage an exclusive resource group for Data Integration and Create and manage a serverless resource group.
-
For recommended resource quota configurations, see Resource group performance metrics - Data Integration.
Step 3: Switch to script mode and import a template
Click the Convert to Script
icon in the toolbar.
If the script has not been configured, you can click the
icon in the toolbar to quickly import a script template by following the on-screen instructions.
Step 4: Edit the script to configure the synchronization task
Common script mode configurations:
-
The type and version fields are default values and cannot be modified.
-
You can ignore the Processor-related configuration in the script (no configuration is required).
{
"type":"job",
"version":"2.0",
"steps":[
{
"stepType":"plugin_name",
"parameter":{...},
"name":"Reader",
"category":"reader"
},
{
"stepType":"plugin_name",
"parameter":{...},
"name":"Writer",
"category":"writer"
}
],
{
"name":"Processor",
"stepType":null,
"category":"processor",
"copies":1,
"parameter":{...}
},
"setting":{
"executeMode":null,
"errorLimit":{
"record":""
},
"speed":{
"concurrent":2,
"throttle":false
},
"timeZone":"Asia/Shanghai"
},
"order":{
"hops":[
{
"from":"Reader",
"to":"Writer"
}
]
}
}
-
Configure the basic information and column mappings for the reader and writer.
ImportantThe configurations vary for different plug-ins. The following content describes only common configurations as examples. Whether a plug-in supports a specific configuration and how the configuration is implemented depend on the plug-in. For details, see the Reader Script Demo and Writer Script Demo for each data source in the list of data sources.
By configuring these parameters, you can:
-
Reader
Configuration
Description
where (configure the synchronization scope)
Some source types support data filtering. You can specify a condition (a
WHEREclause, but you do not need to include the where keyword) to filter source data. During task execution, only data that meets the condition is synchronized. For more information, see Configure a filter condition.To implement incremental synchronization, you can combine the filter condition with scheduling parameters to make it dynamic. For example, by using
gmt_create >= '${bizdate}', the task synchronizes only newly added data each day. You also need to assign a value to the variable defined here when configuring the schedule settings. For more information, see Configure scheduling parameters.The incremental synchronization configuration method varies for different data sources (plug-ins).
If no data filter condition is configured, full data of the table is synchronized by default.
splitPk (configure the split key for relational databases)
Specifies the column used to split source data for parallel reading. During task execution, data is split into multiple tasks based on this column for concurrent batch reads.
-
We recommend that you use the primary key as the splitPk value because primary keys are generally evenly distributed, which helps prevent data hotspots.
-
Currently, splitPk supports only integer-based splitting. Other types such as strings, floating-point numbers, and dates are not supported. If you specify an unsupported type, the splitPk feature is ignored and the data is synchronized through a single channel.
-
If splitPk is not specified, including when the splitPk parameter is not provided or is left empty, the data is synchronized through a single channel.
-
Not all plug-ins support split key configuration. The preceding information is an example only. For details, see the specific plug-in documentation. For more information, see Supported data sources and sync solutions.
column (define source columns)
Define the columns to synchronize from the source in the column array. You can also write constants, variables, and functions as custom columns to the destination, such as '123', '${variable_name}', and 'now()'.
-
-
Writer
Configuration
Description
preSql & postSql (configure pre-sync and post-sync SQL statements)
Some data sources support executing SQL statements on the destination before synchronization (before writing) and after synchronization (after writing).
Example: MySQL Writer supports preSql and postSql configuration, which allows you to execute MySQL commands before or after data is written to MySQL. For example, you can configure the MySQL truncate table command
truncate table tablenamein the Pre-import Preparation Statement (preSql) setting of the MySQL Writer to clear old data from the table before synchronization (before writing data to MySQL).writeMode (define the write mode for conflicts)
Specifies the write mode when conflicts occur, such as path or primary key conflicts. This varies by data source and writer plug-in. See the specific writer plug-in documentation for details.
-
-
Channel Control.
You can configure efficiency settings in the setting section, including concurrency, synchronization speed, and dirty data handling.
Parameter
Description
executeMode (distributed processing)
Controls whether to enable distributed mode.
-
distribute: Enables distributed processing. The task is split into slices distributed to multiple execution nodes for concurrent execution, allowing synchronization speed to scale horizontally with the cluster size beyond single-node limits.
-
null: Disables distributed processing. The configured concurrency applies only to process-level concurrency on a single node, and multi-node computing cannot be used.
Important-
If your exclusive resource group for Data Integration has only one node, distributed mode is not recommended because it cannot leverage multi-node resources.
-
If a single node meets your speed requirements, single-node mode is recommended for simplicity.
-
The concurrency must be 8 or higher to enable distributed processing.
-
Some data sources support distributed mode for task execution. For details, refer to the specific plug-in documentation.
-
Enabling distributed processing consumes more resources. If an out-of-memory (OOM) error occurs during execution, try disabling this option.
concurrent (maximum expected concurrency)
Defines the maximum number of threads for parallel reading from the source or writing to the destination.
NoteDue to factors such as resource specifications, the actual concurrency may be less than or equal to the configured value. The debug resource group is billed based on actual concurrency. For more information, see Billing.
throttle (synchronization speed)
Controls the synchronization speed.
-
true: Enables throttling. This protects the source database by capping extraction speed to prevent overload. The minimum throttling rate is 1 MB/s.
NoteWhen throttle is set to true, you also need to set the mbps (synchronization speed) parameter.
-
false: Disables throttling. The task delivers the maximum transfer performance that the hardware environment allows within the configured concurrency limit.
NoteThe throughput metric is a Data Integration internal measurement and does not represent actual NIC traffic. Typically, NIC traffic is 1 to 2 times the channel traffic. The actual ratio depends on the serialization mechanism of the data storage system.
errorLimit (error count control)
Defines the dirty data threshold and how it affects the task.
ImportantExcessive dirty data can affect the overall synchronization speed of the task.
-
If not configured, dirty data is allowed by default and does not affect task execution.
-
If set to 0, no dirty data is allowed. The task fails if dirty data is generated during synchronization.
-
If dirty data is allowed and a threshold is set:
-
If the dirty data is within the threshold, the synchronization task ignores the dirty data (does not write it to the destination) and continues normally.
-
If the dirty data exceeds the threshold, the synchronization task fails.
-
NoteDirty data criteria: Dirty data is data that has no business significance, has an invalid format, or encounters issues during synchronization. If an exception occurs while writing a record to the destination, that record is considered dirty data.
For example, writing VARCHAR data from the source to an INT column in the destination results in dirty data due to an invalid type conversion. You can control whether dirty data is allowed during synchronization task configuration, and set a maximum error count so that the task fails when the dirty data count exceeds the specified limit.
timeZone (time zone setting)
Specifies the time zone for the synchronization task. This setting takes effect when time-type columns are converted on the source or destination. Data Integration reads and writes time columns based on the specified time zone.
Configuration example:
"timeZone":"Asia/Shanghai".-
This parameter can be configured only in the setting section in script mode. The destination in wizard mode (codeless UI) does not support time zone settings.
-
The time zone value uses the standard IANA time zone format, such as
Asia/ShanghaiandAmerica/New_York. -
If not configured, Data Integration uses the system default time zone.
NoteOverall synchronization speed is also affected by source data source performance, network environment, and other factors. For more information, see Tune batch synchronization tasks.
-
Step 5: Configure schedule settings
For a single-table batch synchronization task with periodic scheduling, you must configure the properties for automatic scheduling. Go to the editing page of the node, click Scheduling Settings on the right side, and configure the schedule settings for the node.
You must configure scheduling parameters, scheduling policies, scheduling time, and dependencies for the synchronization task. The configuration method is the same as that for other data development nodes and is not described here.
For schedule settings in the new version of Data Studio, see Node scheduling (new version).
For schedule settings in legacy Data Studio, see Node scheduling (legacy).
For more information about using scheduling parameters, see Typical scenarios of scheduling parameters in Data Integration.
Step 6: Submit and deploy the task
Configure run parameters.
On the right side of the single-table batch synchronization task configuration page, click Run Configuration and configure the following parameters for test runs.
Configuration item
Description
Resource Group
Select a resource group that has network connectivity with the data sources.
Script Parameters
Assign values to the placeholder parameters in the data synchronization task. For example, if the Data Integration task uses the
${bizdate}parameter, configure a date parameter in theyyyymmddformat.Run the task.
Click the
Run button on the toolbar to run and debug the task in Data Studio. You can then create a node of the corresponding destination table type to query the destination table data and verify whether the synchronized data meets expectations.Deploy the task.
After the task passes the test run, if the task needs to be run periodically, click the
button at the top of the node editing page to deploy the task to the production environment. For more information about task deployment, see Deploy tasks.
Next step
After the task is deployed to the production environment, you can go to the Operation Center in the production environment to view the scheduled task. For more information about running and managing Data Integration tasks, monitoring task status, and managing resource groups, see Data Integration task O&M.