This topic describes how to use the Hologres connector to synchronize data in a YAML data ingestion deployment.
Background
Hologres is a real-time data warehouse engine that supports real-time writes, updates, and analytics at scale. Hologres is compatible with the PostgreSQL protocol and supports standard SQL. It supports online analytical processing (OLAP) and ad hoc queries on petabytes of data, and serves data with high concurrency and low latency. Hologres integrates with MaxCompute, Realtime Compute for Apache Flink, and DataWorks to offer a complete online and offline data warehouse solution. The following table describes the capabilities of the Hologres YAML connector.
Item | Description |
Table type | Sink |
Running mode | Streaming and batch modes |
Data format | N/A |
Metric |
Note For more details, see Metrics. |
API type | YAML |
Updates or deletions in a sink table | Supported |
Features
Feature | Description |
Synchronizes full and incremental data in real time from an entire database or multiple tables to corresponding sink tables. | |
Synchronizes schema changes (such as adding, dropping, or renaming columns) from source tables to corresponding sink tables in real time. | |
Use a regular expression to match source tables across multiple sharded databases by name. Data from these tables is then merged and synchronized to correspondingly named downstream sink tables. | |
Writes data from an upstream table to a Hologres partitioned table. | |
Maps upstream data types to broader Hologres data types using multiple strategies. |
Syntax
sink:
type: hologres
name: Hologres Sink
endpoint: <yourEndpoint>
dbname: <yourDbname>
username: ${secret_values.ak_id}
password: ${secret_values.ak_secret}Parameters
Parameter | Description | Type | Required | Default | Remarks |
type | The sink type. | String | Yes | None | The value must be |
name | The sink name. | String | No | None | N/A. |
dbname | The database name. | String | Yes | None | N/A. |
username | The username for database access. Use the AccessKey ID of your Alibaba Cloud account. | String | Yes | None | For more information, see How do I view the AccessKey ID and AccessKey secret? Important To avoid exposing your AccessKey, specify its values by using variables. For more information, see Project variables. |
password | The password for database access. Use the AccessKey Secret of your Alibaba Cloud account. | String | Yes | None | |
endpoint | The Hologres service endpoint. | String | Yes | None | For more information, see Access endpoints. |
jdbcRetryCount | The number of retries for write and query operations when a connection fails. | Integer | No | 10 | N/A. |
jdbcRetrySleepInitMs | The fixed wait time for each retry attempt. | Long | No | 1000 | Unit: milliseconds. The actual wait time for a retry is calculated by using the following formula: |
jdbcRetrySleepStepMs | The incremental wait time for each retry attempt. | Long | No | 5000 | Unit: milliseconds. The actual wait time for a retry is calculated by using the following formula: |
jdbcConnectionMaxIdleMs | The maximum idle time for a JDBC connection. | Long | No | 60000 | Unit: milliseconds. If a connection is idle for longer than this duration, it is disconnected and released. |
jdbcMetaCacheTTL | The expiration time for locally cached TableSchema information. | Long | No | 60000 | Unit: milliseconds. |
jdbcMetaAutoRefreshFactor | A factor that determines the cache refresh trigger. The system automatically refreshes the cache if its remaining lifetime is less than the trigger time. | Integer | No | 4 | The remaining cache lifetime is calculated as follows: Remaining cache lifetime = Cache expiration time - Time the cache has been active. After an automatic refresh, the cache's active time is reset to 0. The trigger time is calculated by using the formula: |
mutatetype | The data writing mode. | String | No | INSERT_OR_UPDATE | If a primary key is set for the Hologres physical table, the Hologres sink ensures exactly-once semantics based on the primary key. If data with a duplicate primary key arrives, the
|
createparttable | Specifies whether to automatically create non-existent partitions when writing to a partitioned table. | Boolean | No | false | N/A. |
sink.delete-strategy | Specifies how to process retraction messages. | String | No | None | Valid values:
|
jdbcWriteBatchSize | In JDBC mode, the maximum number of records to buffer in the Hologres sink before a batch write. | Integer | No | 256 | Unit: rows. Note The jdbcWriteBatchSize, jdbcWriteBatchByteSize, and jdbcWriteFlushInterval parameters have an OR relationship. If you set all three parameters, the result data is written as soon as one of the conditions is met. |
jdbcWriteBatchByteSize | In JDBC mode, this parameter specifies the maximum size of data in bytes that the Hologres sink buffers before writing the batch to the destination. | Long | No | 2,097,152 bytes (2 MB) | Note The jdbcWriteBatchSize, jdbcWriteBatchByteSize, and jdbcWriteFlushInterval parameters have an OR relationship. If you set all three parameters, the result data is written as soon as one of the conditions is met. |
jdbcWriteFlushInterval | In JDBC mode, this parameter specifies the maximum amount of time the Hologres sink waits before writing buffered data to Hologres. | Long | No | 10000 | Unit: milliseconds. Note The jdbcWriteBatchSize, jdbcWriteBatchByteSize, and jdbcWriteFlushInterval parameters have an OR relationship. If you set all three parameters, the result data is written as soon as the condition for any one of them is met. |
ignoreNullWhenUpdate | Specifies whether to ignore null values in the incoming data when | Boolean | No | false | Valid values:
|
jdbcEnableDefaultForNotNullColumn | Specifies whether to insert a default value when a null is written to a NOT NULL column that lacks a defined default value. | Boolean | No | true | Valid values:
|
remove-u0000-in-text.enabled | Specifies whether to remove the null character ( | Boolean | No | false | Valid values:
|
deduplication.enabled | Specifies whether to perform deduplication within each batch before writing in jdbc and jdbc_fixed modes. | Boolean | No | true | Valid values:
|
sink.type-normalize-strategy | The data type mapping strategy. | String | No | STANDARD | The strategy that the Hologres sink uses to convert upstream data types to Hologres types.
|
sink.insert.legacy-put-handler | Specifies whether to use the legacy Put Handler to write data to Hologres. | Boolean | No | false | Valid values:
|
table_property.* | The physical table properties for Hologres. | String | No | None | When you create a Hologres table, you can set physical table properties in the WITH clause. Appropriate table properties can help the system organize and query data efficiently. Warning The |
connection.ssl.mode | Specifies whether to enable Secure Sockets Layer (SSL) transport encryption and which mode to use. | String | No | disable |
Note
|
connection.ssl.root-cert.location | When the transport encryption mode requires a certificate, specifies the path to the certificate file. | String | No | None | When connection.ssl.mode is set to verify-ca or verify-full, you must also configure the path to the CA certificate. You can upload the certificate to the platform by using the File Management feature in the Realtime Compute console. After the certificate is uploaded, it is stored in the /flink/usrlib directory. For example, if the CA certificate file is named certificate.crt, the parameter value must be Note To obtain a CA certificate, see Transport encryption - Download a CA certificate. |
connection.akv4.enabled | Specifies whether to enable AKV4 mode to connect to the Hologres server. | Boolean | No | false | N/A. |
connection.akv4.region | When AKV4 mode is enabled, specifies the region where the server is located. | String | No | None | For example, |
Reuse an existing Catalog
Starting from VVR 11.5, you can directly reference a built-in Hologres Catalog created on the Data Management page in a Flink CDC data ingestion job. This reduces the need to manually specify connection properties.
sink:
type: hologres
using.built-in-catalog: my_holo_catalogData ingestion jobs can automatically reuse the following Hologres Catalog parameters:
endpoint
username
password
dbname
To override these automatically reused parameters, you can explicitly specify the corresponding YAML parameters, which have a higher priority.
Data type mapping
You can use the parameter sink.type-normalize-strategy to set the strategy for converting upstream data to Hologres types.
Enable
sink.type-normalize-strategywhen you start a YAML job for the first time. If you enable it after the job has started, you must delete the downstream table and restart the job without state for the setting to take effect.Currently, array types support only INTEGER, BIGINT, FLOAT, DOUBLE, BOOLEAN, CHAR, and VARCHAR.
Hologres does not support the numeric type as a primary key. If a primary key's type maps to
numeric, the system converts it to thevarchartype.
STANDARD
When sink.type-normalize-strategy is set to STANDARD, the types are mapped as follows:
Flink CDC type | Hologres type |
CHAR | bpchar |
STRING | text |
VARCHAR | text (if length > 10485760) |
varchar (if length <= 10485760) | |
BOOLEAN | bool |
BINARY | bytea |
VARBINARY | |
DECIMAL | numeric |
TINYINT | int2 |
SMALLINT | |
INTEGER | int4 |
BIGINT | int8 |
FLOAT | float4 |
DOUBLE | float8 |
DATE | date |
TIME_WITHOUT_TIME_ZONE | time |
TIMESTAMP_WITHOUT_TIME_ZONE | timestamp |
TIMESTAMP_WITH_LOCAL_TIME_ZONE | timestamptz |
ARRAY | Arrays of the corresponding element types |
MAP | Not supported |
ROW | Not supported |
BROADEN
When sink.type-normalize-strategy is set to BROADEN, Flink CDC types are converted to wider-range Hologres types. The types are mapped as follows:
Flink CDC type | Hologres type |
CHAR | text |
STRING | |
VARCHAR | |
BOOLEAN | bool |
BINARY | bytea |
VARBINARY | |
DECIMAL | numeric |
TINYINT | int8 |
SMALLINT | |
INTEGER | |
BIGINT | |
FLOAT | float8 |
DOUBLE | |
DATE | date |
TIME_WITHOUT_TIME_ZONE | time |
TIMESTAMP_WITHOUT_TIME_ZONE | timestamp |
TIMESTAMP_WITH_LOCAL_TIME_ZONE | timestamptz |
ARRAY | Arrays of the corresponding element types |
MAP | Not supported |
ROW | Not supported |
ONLY_BIGINT_OR_TEXT
When sink.type-normalize-strategy is set to ONLY_BIGINT_OR_TEXT, all Flink CDC types are converted to BIGINT or STRING types in Hologres. The data type mapping is as follows:
Flink CDC type | Hologres type |
TINYINT | int8 |
SMALLINT | |
INTEGER | |
BIGINT | |
BOOLEAN | text |
BINARY | |
VARBINARY | |
DECIMAL | |
FLOAT | |
DOUBLE | |
DATE | |
TIME_WITHOUT_TIME_ZONE | |
TIMESTAMP_WITHOUT_TIME_ZONE | |
TIMESTAMP_WITH_LOCAL_TIME_ZONE | |
ARRAY | Arrays of the corresponding element types |
MAP | Not supported |
ROW | Not supported |
Writing to partitioned tables
You can use the Hologres sink with a transform to write upstream data to a Hologres partitioned table.
The
partition keymust be part of theprimary key. If you use a non-primary key column from the upstream data as thepartition key, the primary keys of the upstream and downstream tables can become inconsistent, causing data discrepancies during data synchronization.Hologres supports columns of the TEXT, VARCHAR, and INT data types as a
partition key. Since version 1.3.22, columns of the DATE data type are also supported.To automatically create child partitioned tables, set the
createparttableparameter totrue. Otherwise, you must create them manually.
See Writing data to a partitioned table for an example.
Table schema synchronization
A CDC YAML pipeline uses different strategies to handle table schema changes, which are configurable with the pipeline-level schema.change.behavior parameter. Valid values for schema.change.behavior are IGNORE, LENIENT, TRY_EVOLVE, EVOLVE, and EXCEPTION. Hologres Sink does not currently support the TRY_EVOLVE strategy. The LENIENT and EVOLVE strategies involve table schema changes. The following sections describe how these two modes handle different schema change events.
LENIENT (default)
In LENIENT mode, schema changes are handled as follows:
Add a nullable column: The corresponding column is automatically added to the end of the sink table, and its data is synchronized.
Delete a nullable column: The column is not deleted from the sink table. Instead, the column is automatically populated with NULL values.
Add a non-nullable column: A corresponding nullable column is automatically added to the end of the sink table, and its data is synchronized. For existing rows, this new column is automatically populated with NULL.
Rename a column: This operation is treated as deleting a column and adding a new one. A new column with the specified name is added to the end of the sink table, and the column with the original name is automatically populated with NULL values. For example, if col_a is renamed to col_b, a col_b column is added to the end of the sink table, and the col_a column is automatically populated with NULL values.
Change a column's data type: Not supported. As Hologres does not support changing a column's data type, you must use the
sink.type-normalize-strategyparameter.The following schema changes are not supported:
Changes to constraints, such as the primary key or index.
Deleting a non-nullable column.
Changing a column from NOT NULL to NULLABLE.
EVOLVE
In EVOLVE mode, schema changes are handled as follows:
Add a nullable column: Supported.
Delete a nullable column: Not supported.
Add a non-nullable column: A new nullable column is added to the sink table.
Rename a column: Supported. The original column is renamed in the sink table.
Change a column's data type: Not supported. As Hologres does not support changing a column's data type, you must use the
sink.type-normalize-strategyparameter.The following schema changes are not supported:
Changes to constraints, such as the primary key or index.
Deleting a non-nullable column.
Changing a column from NOT NULL to NULLABLE.
In EVOLVE mode, performing a stateless restart without deleting the sink table can cause the pipeline to fail due to schema inconsistencies between the upstream data and the sink table. You must then manually adjust the sink table schema.
See Enabling the EVOLVE mode for an example.
Code examples
Type broadening
Use the sink.type-normalize-strategy parameter to configure type broadening.
source:
type: mysql
name: MySQL Source
hostname: <yourHostname>
port: 3306
username: flink
password: ${secret_values.password}
tables: test_db.test_source_table
server-id: 5401-5499
sink:
type: hologres
name: Hologres Sink
endpoint: <yourEndpoint>
dbname: <yourDbname>
username: ${secret_values.ak_id}
password: ${secret_values.ak_secret}
# Map CDC data types to broader Hologres types.
sink.type-normalize-strategy: BROADEN
pipeline:
name: MySQL to Hologres PipelineWriting to a partitioned table
Convert the create_time timestamp field to a date type and use it as the partition key for the Hologres table.
source:
type: mysql
name: MySQL Source
hostname: <yourHostname>
port: 3306
username: flink
password: ${secret_values.password}
tables: test_db.test_source_table
server-id: 5401-5499
sink:
type: hologres
name: Hologres Sink
endpoint: <yourEndpoint>
dbname: <yourDbname>
username: ${secret_values.ak_id}
password: ${secret_values.ak_secret}
# Automatically create partitioned tables if they do not exist.
createparttable: true
transform:
- source-table: test_db.test_source_table
projection: \*, DATE_FORMAT(CAST(create_time AS TIMESTAMP), 'yyyy-MM-dd') as partition_key
primary-keys: id, create_time, partition_key
partition-keys: partition_key
description: add partition key
pipeline:
name: MySQL to Hologres PipelineEnabling EVOLVE mode
source:
type: mysql
name: MySQL Source
hostname: <yourHostname>
port: 3306
username: flink
password: ${secret_values.password}
tables: test_db.test_source_table
server-id: 5401-5499
sink:
type: hologres
name: Hologres Sink
endpoint: <yourEndpoint>
dbname: <yourDbname>
username: ${secret_values.ak_id}
password: ${secret_values.ak_secret}
# Automatically create partitioned tables if they do not exist.
createparttable: true
pipeline:
name: MySQL to Hologres Pipeline
schema.change.behavior: evolveSingle-table synchronization
source:
type: mysql
name: MySQL Source
hostname: <yourHostname>
port: 3306
username: flink
password: ${secret_values.password}
tables: test_db.test_source_table
server-id: 5401-5499
sink:
type: hologres
name: Hologres Sink
endpoint: <yourEndpoint>
dbname: <yourDbname>
username: ${secret_values.ak_id}
password: ${secret_values.ak_secret}
# Map CDC data types to broader Hologres types.
sink.type-normalize-strategy: BROADEN
pipeline:
name: MySQL to Hologres PipelineFull database synchronization
source:
type: mysql
name: MySQL Source
hostname: <yourHostname>
port: 3306
username: flink
password: ${secret_values.password}
tables: test_db.\.*
server-id: 5401-5499
sink:
type: hologres
name: Hologres Sink
endpoint: <yourEndpoint>
dbname: <yourDbname>
username: ${secret_values.ak_id}
password: ${secret_values.ak_secret}
# Map CDC data types to broader Hologres types.
sink.type-normalize-strategy: BROADEN
pipeline:
name: MySQL to Hologres PipelineMerging sharded tables
source:
type: mysql
name: MySQL Source
hostname: <yourHostname>
port: 3306
username: flink
password: ${secret_values.password}
tables: test_db.user\.*
server-id: 5401-5499
sink:
type: hologres
name: Hologres Sink
endpoint: <yourEndpoint>
dbname: <yourDbname>
username: ${secret_values.ak_id}
password: ${secret_values.ak_secret}
# Map CDC data types to broader Hologres types.
sink.type-normalize-strategy: BROADEN
route:
# All sharded tables in the MySQL test_db database are merged into a single Hologres table named test_db.user.
- source-table: test_db.user\.*
sink-table: test_db.user
pipeline:
name: MySQL to Hologres PipelineSynchronizing to a specified schema
In Hologres, a schema corresponds to a database in MySQL. You can specify the schema for the sink tables.
source:
type: mysql
name: MySQL Source
hostname: <yourHostname>
port: 3306
username: flink
password: ${secret_values.password}
tables: test_db.user\.*
server-id: 5401-5499
sink:
type: hologres
name: Hologres Sink
endpoint: <yourEndpoint>
dbname: <yourDbname>
username: ${secret_values.ak_id}
password: ${secret_values.ak_secret}
# Map CDC data types to broader Hologres types.
sink.type-normalize-strategy: BROADEN
route:
# Synchronize all tables from the MySQL test_db database to the Hologres test_db2 schema while keeping the original table names.
- source-table: test_db.\.*
sink-table: test_db2.<>
replace-symbol: <>
pipeline:
name: MySQL to Hologres PipelineSynchronizing new tables without restart
To synchronize newly added tables in real time while a job is running, set scan.binlog.newly-added-table.enable = true.
source:
type: mysql
name: MySQL Source
hostname: <yourHostname>
port: 3306
username: flink
password: ${secret_values.password}
tables: test_db.\.*
server-id: 5401-5499
# Automatically captures new tables created while the job is running.
scan.binlog.newly-added-table.enabled: true
sink:
type: hologres
name: Hologres Sink
endpoint: <yourEndpoint>
dbname: <yourDbname>
username: ${secret_values.ak_id}
password: ${secret_values.ak_secret}
# Map CDC data types to broader Hologres types.
sink.type-normalize-strategy: BROADEN
pipeline:
name: MySQL to Hologres PipelineAdding existing tables on restart
To include an existing table in the synchronization, set scan.newly-added-table.enabled to true and restart the job.
Do not use scan.newly-added-table.enabled on a job that was previously run with scan.binlog.newly-added-table.enabled. This combination causes data duplication on restart.
source:
type: mysql
name: MySQL Source
hostname: <yourHostname>
port: 3306
username: flink
password: ${secret_values.password}
tables: test_db.\.*
server-id: 5401-5499
scan.startup.mode: initial
# On restart, the job scans for new tables matching the `tables` parameter and performs a snapshot.
# Note: This parameter must be used with scan.startup.mode: initial.
scan.newly-added-table.enabled: true
sink:
type: hologres
name: Hologres Sink
endpoint: <yourEndpoint>
dbname: <yourDbname>
username: ${secret_values.ak_id}
password: ${secret_values.ak_secret}
# Map CDC data types to broader Hologres types.
sink.type-normalize-strategy: BROADEN
pipeline:
name: MySQL to Hologres PipelineExcluding tables
source:
type: mysql
name: MySQL Source
hostname: <yourHostname>
port: 3306
username: flink
password: ${secret_values.password}
tables: test_db.\.*
# Excludes tables that match this regular expression.
tables.exclude: test_db.table1
server-id: 5401-5499
sink:
type: hologres
name: Hologres Sink
endpoint: <yourEndpoint>
dbname: <yourDbname>
username: ${secret_values.ak_id}
password: ${secret_values.ak_secret}
# Map CDC data types to broader Hologres types.
sink.type-normalize-strategy: BROADEN
pipeline:
name: MySQL to Hologres PipelineRelated documents
To learn more about source, sink, transform, and route modules, see Flink CDC Data Ingestion Job Development Reference.
To develop a data ingestion YAML job, see Flink CDC Data Ingestion Job Development.