Import table data into Alibaba Cloud SelectDB by using the Data Integration feature of DataWorks with the ApsaraDB for SelectDB. This example uses MySQL as the data source to synchronize data to ApsaraDB for SelectDB.
Limitations
-
The Data Integration feature of DataWorks supports only ApsaraDB for SelectDB to Alibaba Cloud SelectDB.
-
Writing data to BITMAP, HLL (HyperLogLog), and QUANTILE_STATE fields is not supported.
Data synchronization task development
Add data sources
Before developing a data synchronization task, create a MySQL data source and a SelectDB data source in DataWorks.
-
Create a MySQL data source. For more information, see MySQL Data Source.
-
Create a SelectDB data source. For more information, see Data Source Management. The following table lists the key parameters.
Parameter
Description
Data source name
The name of the data source.
MySQL connection string
The JDBC connection string:
jdbc:mysql://<ip>:<port>/<dbname>.In the ApsaraDB for SelectDB console, go to the Instance Details > Network Information page to obtain the VPC Endpoint (or Public Endpoint) and MySQL Port.
Example:
jdbc:mysql://selectdb-cn-4xl3jv1****.selectdbfe.rds.aliyuncs.com:9030/test_dbNoteIf the MySQL instance and the ApsaraDB for SelectDB instance are in the same VPC, use the VPC Endpoint. Otherwise, use the Public Endpoint.
HTTP connection address
The HTTP connection address:
<ip>:<port>.In the ApsaraDB for SelectDB console, go to the Instance Details > Network Information page to obtain the VPC Endpoint (or Public Endpoint) and HTTP Port.
Example:
selectdb-cn-4xl3jv1****.selectdbfe.rds.aliyuncs.com:8080NoteIf the MySQL instance and the ApsaraDB for SelectDB instance are in the same VPC, use the VPC Endpoint. Otherwise, use the Public Endpoint.
Username
Enter the username for your ApsaraDB for SelectDB instance.
Password
Enter the password for the user of your ApsaraDB for SelectDB instance.
ImportantTo add the data source, add the IP addresses of the DataWorks resource group to the whitelist of data sources such as SelectDB. For more information, see Add IP addresses to a whitelist. When you configure the whitelist, distinguish between exclusive and shared Data Integration resource groups.
Configure single-table offline synchronization
You can configure an offline synchronization task in either wizard mode or script mode. For more information, see the following topics:
-
For a complete list of parameters and a script sample for script mode, see Script mode: samples and parameters.
Script mode: samples and parameters
Offline task script configuration
When configuring an offline task in script mode, use the format detailed in Script mode configuration.
MySQL Reader and SelectDB Writer script sample
{
"type":"job",
"version":"2.0",
"steps":[
{
"stepType":"mysql",
"parameter":{
"column":[
"<id>",
"<table_id>",
"<table_no>",
"<table_name>",
"<table_status>"
],
"connection":[
{
"datasource":"<mysql_datasource>",
"table":[
"<mysql_table_name>"
]
}
],
"where":"",
"splitPk":"",
"encoding":"UTF-8"
},
"name":"Reader",
"category":"reader"
},
{
"stepType":"selectdb",
"parameter":{
"postSql":[
],
"preSql":[
],
"username": "<selectdb_username>",
"password": "<selectdb_password>",
"loadUrl":[
"<ip:port>"
],
"column":[
"<id>",
"<table_id>",
"<table_no>",
"<table_name>",
"<table_status>"
],
"connection":[
{
"datasource":"<selectdb_datasource>",
"table":[
"<selectdb_table_name>"
]
}
],
"maxBatchRows":1000000,
"loadProps":{
"format":"csv",
"column_separator": "\\x01",
"line_delimiter": "\\x02"
}
},
"name":"Writer",
"category":"writer"
}
],
"setting":{
"errorLimit":{
"record":"0"
},
"speed":{
"throttle":false,
"concurrent":1
}
},
"order":{
"hops":[
{
"from":"Reader",
"to":"Writer"
}
]
}
}
Script parameters
|
Parameter |
Description |
|
datasource |
Required. The name of the DataWorks data source. This value must match the name of the source you created. |
|
table |
Required. The name of the destination table. |
|
column |
Required. The destination columns to write data to, separated by commas (,). For example: |
|
loadUrl |
Required. The HTTP endpoint of the SelectDB FE cluster. The format is |
|
username |
Required. The username for the SelectDB database. |
|
password |
Required. The password for the SelectDB database user. |
|
preSql |
SQL statements to execute before the synchronization task begins. Wizard mode supports one statement, while script mode supports multiple (e.g., for clearing a table). |
|
postSql |
SQL statements to execute after the synchronization task completes. Wizard mode supports one statement, while script mode supports multiple (e.g., for adding a timestamp). |
|
maxBatchRows |
The maximum number of rows to import per batch. The default value is 500,000. |
|
loadProps |
Request parameters for COPY INTO that specify the imported data format. Default: JSON. If loadProps is not configured or is set to
To use CSV format, specify the format and configure row and column delimiters as shown below. If not specified, columns default to tab-separated (
|
Supported data types
ApsaraDB for SelectDB supports the following data types.
|
SelectDB data type |
Offline write |
|
INT |
Supported |
|
BIGINT |
Supported |
|
LARGEINT |
Supported |
|
SMALLINT |
Supported |
|
TINYINT |
Supported |
|
BOOLEAN |
Supported |
|
DECIMAL |
Supported |
|
DOUBLE |
Supported |
|
FLOAT |
Supported |
|
CHAR |
Supported |
|
VARCHAR |
Supported |
|
STRING |
Supported |
|
DATE |
Supported |
|
DATEV2 |
Supported |
|
DATETIME |
Supported |
|
DATETIMEV2 |
Supported |
|
ARRAY |
Supported |
|
JSONB |
Supported |
|
BITMAP |
Not supported |
|
HLL (HyperLogLog) |
Not supported |
|
QUANTILE_STATE |
Not supported |