This topic describes how to migrate data from MaxCompute to Tablestore by using the data integration feature of DataWorks.
Prerequisites
Before you begin, make sure that you have:
An Alibaba Cloud account with sufficient permissions
A DataWorks workspace created and associated with your MaxCompute project
Procedure
Step 1: Create a source table in MaxCompute
Log on to the DataWorks console and select a region in the upper-left corner.
In the left navigation pane, click Workspace.
On the Workspaces page, find the target workspace. In the Actions column, choose Shortcuts > Data Development.
On the Data Studio page, create an ODPS SQL node and run the following statement to create a table named
transs:CREATE TABLE transs (name STRING, id STRING, gender STRING);
Step 2: Import data into the source table
Save the following sample data to a CSV file on your computer:
qwe,145,F asd,256,F xzc,345,M rgth,234,F ert,456,F dfg,12,M tyj,4,M bfg,245,M nrtjeryj,15,F rwh,2344,M trh,387,F srjeyj,67,M saerh,567,MIn the left navigation pane, choose Data Integration > Data Upload and Download.
In the left navigation pane, click the upload icon
and then click Upload Data.Follow the on-screen instructions to upload the CSV file to the
transstable.
Step 3: Create a destination table in Tablestore
Log on to the Tablestore console and create an instance.
Create a data table named
transwith the following primary keys: For more information, see Create a data table.Primary key Type nameSTRING idINTEGER
Step 4: Add data sources in DataWorks
Add a MaxCompute data source
Log on to the DataWorks console and select a region in the upper-left corner.
In the left navigation pane, click Workspace.
On the Workspaces page, click the name of the target workspace.
On the Workspace Details page, click Data Sources in the left navigation pane.
On the Data Source tab, click Add Data Source and select MaxCompute.
On the Add MaxCompute Data Source page, configure the Basic Information. For more information, see Configure a MaxCompute data source.
Add a Tablestore data source
Add a Tablestore data source in DataWorks. For more information, see Configure a Tablestore data source.
Step 5: Create and run a batch synchronization job
Log on to the DataWorks console and select a region in the upper-left corner.
In the left navigation pane, choose Data Development and O&M > Data Development.
In the Select Workspace section, click Go to Data Studio.
In the left pane of Data Studio, click the
icon and select Create Node > Data Integration > Batch Synchronization.In the Create Node dialog, configure the following required fields: Click Confirm.
Field Value Source Type MaxCompute(ODPS) Destination Type Tablestore Name Enter a name for the node On the node configuration page, configure the following parameters: Keep the default values for all other parameters.
Parameter Value Data Source - Source The MaxCompute data source that you added Data Source - Destination The Tablestore data source that you added Source - Table The MaxCompute table ( transs)Destination - Table The Tablestore table ( trans)Runtime Resource The resource group for Data Integration Click the Run icon in the toolbar to run the batch synchronization job.
Script mode (alternative)
You can also click the
icon above the configuration section to switch to the code editor. The following JSON shows an example configuration:
{
"type": "job",
"steps": [
{
"stepType": "odps",
"parameter": {
"partition": [],
"datasource": "odps_first",
"column": [
"name",
"id",
"gender"
],
"table": "transs"
},
"name": "Reader",
"category": "reader"
},
{
"stepType": "ots",
"parameter": {
"datasource": "transs",
"column": [
{
"name": "gender",
"type": "STRING"
}
],
"writeMode": "UpdateRow",
"table": "trans",
"primaryKey": [
{
"name": "name",
"type": "STRING"
},
{
"name": "id",
"type": "INT"
}
]
},
"name": "Writer",
"category": "writer"
}
],
"version": "2.0",
"order": {
"hops": [
{
"from": "Reader",
"to": "Writer"
}
]
},
"setting": {
"errorLimit": {
"record": "0"
},
"speed": {
"throttle": false,
"concurrent": 1
}
}
}The following table describes the script parameters:
| Parameter | Description |
|---|---|
stepType | The plugin type. odps for MaxCompute (ODPS) Reader. ots for Tablestore (OTS) Writer. |
datasource | The name of the data source registered in DataWorks. |
column | The columns to read or write. For the Reader, specify the column names. For the Writer, specify only the non-primary-key attribute columns with name and data type. |
table | The table name. transs for the source table. trans for the destination table. |
primaryKey | The primary key columns of the Tablestore table, with name and type. |
writeMode | The write mode. UpdateRow updates an existing row or inserts a new row. |
errorLimit.record | The maximum number of error records allowed. "0" means no errors are tolerated. |
speed.concurrent | The number of concurrent channels for the sync job. |
speed.throttle | Whether to enable bandwidth throttling. false disables throttling. |
Step 6: Verify the migrated data
After the sync job runs, verify that the data is migrated to Tablestore.
Log on to the Tablestore console and select a region in the upper-left corner.
In the left navigation pane, click All Instances.
On the All Instances page, click the instance name to go to the Instance Management page.
Click the Instance Details tab.
In the Tables section, click the name of the
transdata table.On the data table management page, click the Query Data tab to view the migrated data.