All Products
Search
Document Center

DataWorks:GBase 8a data source

Last Updated:Nov 10, 2023

DataWorks provides GBase 8a Reader and GBase 8a Writer for you to read data from and write data to GBase 8a data sources. This topic describes the capabilities of synchronizing data from or to GBase 8a data sources.

Limits

  • GBase 8a Reader and GBase 8a Writer support only exclusive resource groups for Data Integration.

  • INSERT INTO: If a primary key conflict or unique index conflict occurs, data cannot be written to conflicting rows.

  • Data can be written to tables stored only in the primary database.

    Note

    A synchronization task that uses GBase 8a Writer must have at least the permissions to execute INSERT INTO. Whether other permissions are required depends on the SQL statements specified in the preSql and postSql parameters when you configure the task.

  • GBase 8a Writer does not support the writeMode parameter.

Develop a data synchronization task

For information about the entry point for and the procedure of configuring a data synchronization task, see the following sections. For information about the parameter settings, view the infotip of each parameter on the configuration tab of the task.

Add a data source

Before you configure a data synchronization task to synchronize data from or to a specific data source, you must add the data source to DataWorks. For more information, see Add and manage data sources.

Configure a batch synchronization task to synchronize data of a single table

Appendix: Code and parameters

Appendix: Configure a batch synchronization task by using the code editor

If you use the code editor to configure a batch synchronization task, you must configure parameters for the reader and writer of the related data source based on the format requirements in the code editor. For more information about the format requirements, see Configure a batch synchronization task by using the code editor. The following information describes the configuration details of parameters for the reader and writer in the code editor.

Code for GBase 8a Reader

{
    "type": "job",
    "steps": [
        {
            "stepType": "gbase8a", // The plug-in name. 
            "parameter": {
                "datasource": "", // The name of the data source. 
                "username": "",
                "password": "",
                "where": "",
                "column": [ // The names of the columns. 
                    "id",
                    "name"
                ],
                "splitPk": "id",
                "connection": [
                    {
                        "table": [ // The name of the table. 
                            "table"
                        ],
                        "datasource":""
                    }
                ]
            },
            "name": "Reader",
            "category": "reader"
        },
        {
            "stepType": "stream",
            "parameter": {
                "print": false,
                "fieldDelimiter": ","
            },
            "name": "Writer",
            "category": "writer"
        }
    ],
    "version": "2.0",
    "order": {
        "hops": [
            {
                "from": "Reader",
                "to": "Writer"
            }
        ]
    },
    "setting": {
        "errorLimit": {
            "record": "0" // The maximum number of dirty data records allowed. 
        },
        "speed": {
            "throttle": true, // Specifies whether to enable throttling. The value false indicates that throttling is disabled, and the value true indicates that throttling is enabled. The mbps parameter takes effect only when the throttle parameter is set to true. 
            "concurrent": 1, // The maximum number of parallel threads. 
            "mbps":"12"// The maximum transmission rate. Unit: MB/s. 
        }
    }
}

Parameters in code for GBase 8a Reader

Parameter

Description

Required

Default value

datasource

The name of the data source. If the edition of the DataWorks service that you activated supports GBase 8a data sources, you can add a GBase 8a data source and specify the data source in this parameter.

No

No default value

table

The name of the table from which you want to read data. GBase 8a Reader can read data from multiple tables. Specify the table names in a JSON array.

If you specify multiple tables, you must make sure that the tables have the same schema. GBase 8a Reader does not check whether the tables have the same schema.

Note

The table parameter must be included in the connection parameter.

Yes

No default value

column

The names of the columns from which you want to read data. Specify the names in a JSON array. The default value is [ * ], which indicates all columns in the source table.

  • You can select specific columns to read.

  • The column order can be changed. This indicates that you can specify columns in an order different from the order specified by the schema of the source table.

  • Constants are supported, such as '123'.

  • Functions are supported, such as date('now').

  • The column parameter must explicitly specify all the columns from which you want to read data. This parameter cannot be left empty.

Yes

No default value

splitPk

The field that is used for data sharding when GBase 8a Reader reads data. If you configure this parameter, the source table is sharded based on the value of this parameter. Data Integration then runs parallel threads to read data. This way, data can be synchronized more efficiently.

  • We recommend that you set the splitPk parameter to the name of the primary key column of the table. Data can be evenly distributed to different shards based on the primary key column, instead of being intensively distributed only to specific shards.

  • The splitPk parameter supports sharding for data only of integer data types. If you set the splitPk parameter to a field of an unsupported data type, such as a string, floating point, or date data type, the setting of this parameter is ignored, and a single thread is used to read data.

  • If you leave the splitPk parameter empty, a single thread is used to read data.

No

No default value

where

The WHERE clause. GBase 8a Reader generates an SQL statement based on the settings of the column, table, and where parameters and uses the generated statement to read data.

For example, when you perform a test, you can set the where parameter to limit 10. To read the data that is generated on the current day, you can set the where parameter to gmt_create > $bizdate.

  • You can use the WHERE clause to read incremental data.

  • If the where parameter is not provided or is left empty, all data is read.

No

No default value

querySql

The SQL statement that is used for refined data filtering. If you configure this parameter, data is filtered based only on the value of this parameter.

If you configure the querySql parameter, GBase 8a Reader ignores the settings of the table, column, where, and splitPk parameters.

No

No default value

fetchSize

The number of data records to read at a time. This parameter determines the number of interactions between Data Integration and the database and affects read efficiency.

Note

If you set this parameter to a value greater than 2048, an out of memory (OOM) error may occur during data synchronization.

No

1,024

Code for GBase 8a Writer

{
    "type":"job",
    "version":"2.0",// The version number. 
    "steps":[
        {
            "stepType":"stream",
            "parameter":{},
            "name":"Reader",
            "category":"reader"
        },
        {
            "stepType":"gbase8a",// The plug-in name. 
            "parameter":{
                "datasource": "The name of the data source",
                "username": "",
                "password": "",
                "column": [// The names of the columns. 
                    "id",
                    "name"
                ],
                "connection": [
                    {
                        "table": [// The name of the table. 
                            "Gbase8a_table"
                        ],
                        "datasource":""
                    }
                ],
                "preSql": [ // The SQL statement that you want to execute before the synchronization task is run. 
                    "delete from @table where db_id = -1"
                ],
                "postSql": [// The SQL statement that you want to execute after the synchronization task is run. 
                    "update @table set db_modify_time = now() where db_id = 1"
                ]
            },
            "name":"Writer",
            "category":"writer"
        }
    ],
    "setting":{
        "errorLimit":{
            "record":"0"// The maximum number of dirty data records allowed. 
        },
        "speed":{
            "throttle":true,// Specifies whether to enable throttling. The value false indicates that throttling is disabled, and the value true indicates that throttling is enabled. The mbps parameter takes effect only when the throttle parameter is set to true. 
            "concurrent":1, // The maximum number of parallel threads. 
            "mbps":"12"// The maximum transmission rate. Unit: MB/s. 
        }
    },
    "order":{
        "hops":[
            {
                "from":"Reader",
                "to":"Writer"
            }
        ]
    }
}

Parameters in code for GBase 8a Writer

Parameter

Description

Required

Default value

datasource

The name of the data source. It must be the same as the name of the added data source. You can add data sources by using the code editor.

Yes

No default value

table

The name of the table to which you want to write data. Specify the name in a JSON array.

Note

The table parameter must be included in the connection parameter.

Yes

No default value

column

The names of the columns to which you want to write data. Separate the names with commas (,), such as "column": ["id", "name", "age"].

Note

The column parameter cannot be left empty.

Yes

No default value

preSql

The SQL statement that you want to execute before the synchronization task is run. Use @table to indicate the name of the destination table in the SQL statement. When you execute this SQL statement, @table is replaced by the name of the destination table.

No

No default value

postSql

The SQL statement that you want to execute after the synchronization task is run.

No

No default value

batchSize

The number of data records to write at a time. Set this parameter to an appropriate value based on your business requirements. This greatly reduces the interactions between Data Integration and GBase 8a and increases throughput. If you set this parameter to an excessively large value, an OOM error may occur during data synchronization.

No

1,024