Export data by using DataWorks
You can use the Data Integration feature of DataWorks to export MaxCompute data to other data sources in batch mode.
Overview
Data Integration supports the following two export methods:
-
Codeless UI mode: After you create a batch synchronization node, configure the source, destination, and field mappings in the DataWorks console to export data.
-
Script mode: After you create a batch synchronization node, switch to script mode in DataWorks and use scripts to configure the source, destination, and field mappings to export data.
Prerequisites
Before you begin, make sure the following prerequisites are met:
-
The table data to export is prepared in MaxCompute.
To create tables and write data, see Table operations and INSERT INTO | INSERT OVERWRITE.
-
The destination data source and destination table are prepared.
Limits
Each batch synchronization node can export data from only one table. To export data from multiple tables, create multiple batch synchronization nodes.
Procedure
To export MaxCompute data by using Data Integration, perform the following steps:
-
Add the MaxCompute data source to the DataWorks data source list.
-
Add the destination data source to the DataWorks data source list.
-
Create a workflow in DataWorks to prepare for batch synchronization.
-
Create a batch synchronization node
Create a batch synchronization node in the workflow.
-
Configure and run a synchronization task in codeless UI mode or Configure and run a synchronization task in script mode
Configure and run the batch synchronization task in codeless UI mode or script mode.
-
Verify synchronization results
Verify the synchronization results in the destination data source.
Add a MaxCompute data source
For the detailed procedure, see Associate a MaxCompute compute resource.
Add a destination data source
Based on the destination data source type, add the data source by following the instructions in Configure data sources.
Create a workflow
Create a workflow in DataWorks to prepare for creating batch synchronization tasks.
-
Log on to the DataWorks console. In the target region, click in the left-side navigation pane. Select a workspace from the drop-down list and click Go to Data Development.
-
On the Data Studio page, move the pointer over the
icon and click Create Workflow. -
In the Create Workflow dialog box, enter the Business Name and Description.
-
Click Create.
Create a batch synchronization node
Create a batch synchronization node in the workflow that you created.
-
Expand the workflow and right-click Data Integration.
-
Click .
-
In the Create Node dialog box, enter a Node Name and select a Path.
ImportantThe node name can contain letters, Chinese characters, digits, underscores (_), and periods (.), and cannot exceed 128 characters.
-
Click Confirm.
Configure and run a synchronization task in codeless UI mode
-
Configure network and resources.
-
Select the data source.
From the Source drop-down list, select MaxCompute(ODPS) as the data source type and select the MaxCompute Data Source Name.
-
Select an exclusive resource group for Data Integration.
Select the exclusive resource group for Data Integration that you created. For more information, see Use an exclusive resource group for Data Integration.
-
Select the destination.
From the Destination drop-down list, select the destination data source type and name.
-
Test connectivity.
Test the network connectivity between the resource group and the source and destination to make sure the exclusive resource group for Data Integration can connect to the data sources. Then, click Next. On the Network and Resource Configuration page, select MaxCompute (ODPS) as the Source on the left, select OSS as the Destination on the right, and select Exclusive Resource Group for the resource group. Click the Test Connectivity buttons on both sides and verify that a green check mark and a "Connected" status are displayed.
-
-
Configure the task.
-
Configure the source and destination.
In the Source and Destination sections, configure the tables and data range for the task. Configure the source and destination.
-
Configure field mappings.
After you select the source and destination, specify the column mappings between the reader and writer. The task writes source fields to the corresponding destination fields based on the mappings. Configure field mappings.
-
Configure channel settings.
Configure channel settings to control synchronization properties. Configure channels.
-
-
Configure scheduling properties.
Configure scheduling parameters in the synchronization task for data filtering.
-
In the top toolbar, click the
icon and then click the
icon to run the batch synchronization task.
Configure and run a synchronization task in script mode
-
Configure network and resources.
Select the data source, destination, and resource group for the synchronization task, and test connectivity. For the detailed procedure, see Configure and run a synchronization task in codeless UI mode.
-
Switch to script mode and import a template.
Click the script conversion icon in the toolbar. If the script is not configured, click the
icon in the toolbar to import a script template. In the top toolbar of the batch synchronization task configuration page, click the </> Script icon to switch to script mode and import a template. -
Edit the script to configure the synchronization task.
-
Configure the reader.
Configure the data source and table information for the reader in the script.
{ "stepType": "odps", "parameter": { "partition": [], "datasource": "odps_first", "envType": 0, "column": [ "*" ], "table": "" }, "name": "Reader", "category": "reader" },-
stepType: The data source type. Set to odps.
-
partition: The partition information of the table. Run the
show partitions <table_name>;command to view partition information. View partitions. -
datasource: The name of the MaxCompute data source.
-
column: The column names of the table to export.
-
table: The name of the table to export. Run the
show tables;command to view table names. -
name and category: Set to Reader to identify this as the reader.
-
-
Configure the writer.
Configure the destination data source and table information for the writer in the script.
{ "stepType":"oss", "parameter":{ "partition":"", "truncate":true, "datasource":"", "column":[ "*" ], "table":"" }, "name":"Writer", "category":"writer" }-
stepType: The destination data source type.
-
partition: The partition information of the destination table.
-
datasource: The name of the destination data source.
-
column: The column names of the destination table.
-
table: The name of the destination table.
-
name and category: Set to Writer to identify this as the writer.
-
-
Configure the maximum job speed, dirty data threshold, and other settings.
"setting": { "errorLimit": { "record": "1024" }, "speed": { "throttle": false, "concurrent": 1 } },-
record: The maximum number of dirty data records allowed.
-
throttle: Specifies whether to enable throttling.
-
concurrent: The maximum number of threads for parallel reads from the source or parallel writes to the destination.
-
For more configuration parameters, see Edit the script to configure the task.
-
-
Configure scheduling properties. For more information, see Scheduling parameter formats.
-
In the top toolbar, click the
icon and then click the
icon to run the batch synchronization task.
Verify synchronization results
Go to the destination data source to verify that the data from the MaxCompute table is exported to the destination table:
-
If the data is complete, the synchronization is successful.
-
If the synchronization fails or data is missing, see Batch synchronization FAQ.
Scenario: Synchronizing data to an on-premises database
Use this approach if you need to back up MaxCompute data to an on-premises database such as MySQL or PostgreSQL, or synchronize MaxCompute data to a local database environment on a recurring schedule. DataWorks Data Integration is well suited for scheduled batch synchronization with visual, no-code configuration.
Prerequisites
Before configuring the synchronization task, make sure the following requirements are met:
-
Network connectivity: The exclusive resource group for Data Integration must be connected to the on-premises database network. Use a dedicated line (Express Connect) or VPN to establish connectivity between Alibaba Cloud and your on-premises environment.
-
The required ports on the destination database are open (3306 by default for MySQL and 5432 by default for PostgreSQL), and the outbound IP address of the exclusive resource group has been added to the destination database's access whitelist.
-
The on-premises database must be accessible from Alibaba Cloud. Have the JDBC connection information ready, including the host, port, database name, username, and password.
Key configuration steps
-
Add the on-premises database as a destination data source
Before creating a synchronization task, add the on-premises MySQL or PostgreSQL instance as a data source in DataWorks. Provide the JDBC connection string (for example,
jdbc:mysql://<host>:<port>/<database>orjdbc:postgresql://<host>:<port>/<database>), username, and password. For the procedure, see Configure data sources. -
Configure the source and destination
When configuring the batch synchronization node, set the following:
-
From the Source drop-down list, select MaxCompute(ODPS) as the data source type and select the MaxCompute data source name.
-
From the Destination drop-down list, select MySQL (or PostgreSQL) and select the on-premises data source you added.
-
-
Configure field mappings and scheduling
Map the MaxCompute table columns to the corresponding destination table columns. Configure a scheduling cycle (for example, daily) to run the synchronization task automatically.
For the JDBC connection to the destination database, set Host to a private network address that is accessible over a dedicated line or VPN. Do not use a public network address. This ensures network connectivity and reduces data transfer risks.
Comparison with Tunnel download
|
Approach |
Best for |
Output target |
|
DataWorks Data Integration |
Scheduled, recurring synchronization |
Destination database (direct write) |
|
Tunnel download |
One-time manual export |
Local files (requires a separate database import step) |
For the Tunnel download approach, see Use the MaxCompute client or MaxCompute Studio.