MaxCompute YAML connector (Beta)

Updated at:

This topic describes how to use the MaxCompute connector as the sink of a data ingestion YAML job.

Prerequisites

  • A MaxCompute project is created. Obtain the project name on the Workspaces > Project management page of the MaxCompute console.

  • The endpoint is determined based on the region and network connection method of the project. For the values for each region and network, see Endpoint.

Limitations

  • Supported only in VVR 11.1 and later.

  • Supported only as a sink.

  • If the MaxCompute project does not support the schema model, each synchronization job can synchronize only one MySQL database, taking an upstream MySQL database as an example. The same applies to other data sources. The connector ignores the tableId.namespace information.

  • If the downstream MaxCompute table already exists, the connector writes with the existing table schema and does not create the table again. If the existing table schema differs from the upstream table schema, a type validation error occurs. For jobs that start without state, delete the downstream table in advance so that the job creates it automatically. A deleted table can be restored with the backup and restore feature within the MaxCompute backup retention period (1 day by default).

Syntax

source:
  type: mysql

sink:
  type: maxcompute
  name: MaxComputeSink
  access-id: ${your_accessId}
  access-key: ${your_accessKey}
  endpoint: ${your_maxcompute_endpoint}
  project: ${your_project}
  buckets-num: 8

Configuration options

Option

Required

Default value

Type

Description

Basic

type

Yes

None

String

Connector to use. Set this to maxcompute.

name

No

None

String

Sink name.

Connection and authentication

access-id

Yes

None

String

AccessKey ID of your Alibaba Cloud account or RAM user.

access-key

Yes

None

String

AccessKey secret that corresponds to the AccessKey ID.

endpoint

Yes

None

String

MaxCompute endpoint.

project

Yes

None

String

MaxCompute project name.

tunnel.endpoint

No

None

String

Endpoint of the MaxCompute Tunnel service. This configuration is usually routed automatically based on the region of the specified project. Use this configuration only in special network environments such as proxies.

quota.name

No

None

String

Name of the exclusive resource group used for MaxCompute data transmission. If this configuration is not specified, the shared resource group is used. This parameter takes effect only when endpoint is set to a VPC address. It does not take effect when endpoint is set to a public address or tunnel.endpoint is specified. For details, see Purchase and use an exclusive data transmission resource group.

sts-token

No

None

String

Specify this parameter to authenticate with a short-term access token (STS token) issued by a RAM role.

Write and compression

buckets-num

No

16

Integer

Number of buckets used when MaxCompute Delta tables are created automatically. For details, see Near-real-time data warehouse overview.

total.buffer-size

No

64MB

String

Amount of data buffered in memory. The buffer is per partition (per table for non-partitioned tables). Buffers of different partitions (tables) are independent. When the threshold is reached, data is written to MaxCompute.

bucket.buffer-size

No

4MB

String

Amount of data buffered in memory per bucket. Takes effect only when writing to Delta tables. Buffers of different buckets are independent. When the threshold is reached, the data of the bucket is written to MaxCompute.

commit.thread-num

No

16

Integer

Number of partitions (tables) processed concurrently during checkpoints.

flush.concurrent-num

No

4

Integer

Number of buckets written concurrently when data is written to MaxCompute. Takes effect only when writing to Delta tables.

compress.algorithm

No

zlib

String

Compression algorithm for data written to MaxCompute. Supported values are raw (no compression), zlib, and snappy.

Table location mappings

When the connector creates tables automatically, it maps the location information of source tables to MaxCompute tables as follows.

Object in data ingestion jobs

MaxCompute location

MySQL location

Project parameter in the configuration

Project

none

TableId.namespace

Schema (only when the MaxCompute project supports the schema model; otherwise ignored)

Database

TableId.tableName

Table

Table

Data type mappings

CDC type

MaxCompute type

CHAR

STRING

VARCHAR

STRING

BOOLEAN

BOOLEAN

BINARY/VARBINARY

BINARY

DECIMAL

DECIMAL

TINYINT

TINYINT

SMALLINT

SMALLINT

INTEGER

INTEGER

BIGINT

BIGINT

FLOAT

FLOAT

DOUBLE

DOUBLE

TIME_WITHOUT_TIME_ZONE

STRING

DATE

DATE

TIMESTAMP_WITHOUT_TIME_ZONE

TIMESTAMP_NTZ

TIMESTAMP_WITH_LOCAL_TIME_ZONE(Precision>3)

TIMESTAMP

TIMESTAMP_WITH_LOCAL_TIME_ZONE(Precision<=3)

DATETIME

TIMESTAMP_WITH_TIME_ZONE(Precision>3)

TIMESTAMP

TIMESTAMP_WITH_TIME_ZONE(Precision<=3)

DATETIME

ARRAY

ARRAY

MAP

MAP

ROW

STRUCT

Schema changes

CDC YAML pipeline jobs use the pipeline-level option schema.change.behavior to control schema change synchronization. The schema.change.behavior option takes the following values: IGNORE, LENIENT, TRY_EVOLVE, EVOLVE, and EXCEPTION. This section describes how LENIENT and EVOLVE handle each schema change event. For the behavior of the other values, how to enable a mode, and general examples, see schema change synchronization.

LENIENT (default)

LENIENT mode supports the following schema change policies:

  • Add a nullable column: the column is appended to the end of the sink table schema, and data of the new column is synchronized automatically.

  • Drop a nullable column: the column is not dropped from the sink table. Instead, its data is filled with NULL values automatically.

  • Add a non-nullable column: the column is appended to the end of the sink table schema, and data of the new column is synchronized automatically. The new column is nullable by default, and data written before the column was added is set to NULL automatically.

  • Rename a column: treated as adding a column and dropping a column. The new column is appended to the end of the sink table, and data of the old column is filled with NULL values automatically. For example, if col_a is renamed to col_b, col_b is appended to the end of the sink table and the data of col_a is set to NULL automatically.

  • Change a column type: the data type of the column is changed in the sink table.

  • The following schema changes are not supported:

    • Changing a column from NULLABLE to NOT NULL.

EVOLVE

EVOLVE mode supports the following schema change policies:

  • Add a nullable column: supported.

  • Drop a nullable column: not supported.

  • Add a non-nullable column: a nullable column is added to the sink table.

  • Rename a column: supported. The existing column is renamed in the sink table.

  • Change a column type: the data type of the column is changed in the sink table.

  • The following schema changes are not supported:

    • Changing a column from NULLABLE to NOT NULL.

Enable EVOLVE mode

EVOLVE mode keeps the downstream table schema strictly consistent with the upstream table schema, including operations such as dropping fields and tables as the upstream does. In this mode, if any downstream schema change event cannot be applied, the job may fail over and cannot recover automatically. The following example shows the job configuration:

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
  # (Optional) Synchronize the data of tables created in the incremental phase.
  scan.binlog.newly-added-table.enabled: true
  # (Optional) Synchronize table comments and column comments.
  include-comments.enabled: true
  # (Optional) Assign unbounded chunks first to prevent possible TaskManager out-of-memory errors.
  scan.incremental.snapshot.unbounded-chunk-first.enabled: true
  # (Optional) Enable parse filtering to accelerate reads.
  scan.only.deserialize.captured.tables.changelog.enabled: true

sink:
  type: maxcompute
  name: MaxComputeSink
  access-id: ${your_accessId}
  access-key: ${your_accessKey}
  endpoint: ${your_maxcompute_endpoint}
  project: ${your_project}
  buckets-num: 8

pipeline:
  name: MySQL to MaxCompute Pipeline
  schema.change.behavior: evolve

Configuration examples

The following examples all use MySQL as the source and show configurations for typical scenarios.

Synchronize a single table

For tables with high requirements on real-time performance and stability, configure a single-table synchronization job. This avoids the complexity risks of multi-table synchronization. The following example shows the configuration:

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
  # (Optional) Synchronize table comments and column comments.
  include-comments.enabled: true
  # (Optional) Assign unbounded chunks first to prevent possible TaskManager out-of-memory errors.
  scan.incremental.snapshot.unbounded-chunk-first.enabled: true
  # (Optional) Enable parse filtering to accelerate reads.
  scan.only.deserialize.captured.tables.changelog.enabled: true


sink:
  type: maxcompute
  name: MaxComputeSink
  access-id: ${your_accessId}
  access-key: ${your_accessKey}
  endpoint: ${your_maxcompute_endpoint}
  project: ${your_project}
  buckets-num: 8

pipeline:
  name: MySQL to MaxCompute Pipeline

Synchronize an entire database

Whole-database synchronization reduces the number of synchronization jobs to configure and run, which lowers O&M costs. The following example shows the configuration:

source:
  type: mysql
  name: MySQL Source
  hostname: <yourHostname>
  port: 3306
  username: flink
  password: ${secret_values.password}
  tables: test_db.\.*
  server-id: 5401-5499
  # (Optional) Synchronize the data of tables created in the incremental phase.
  scan.binlog.newly-added-table.enabled: true
  # (Optional) Synchronize table comments and column comments.
  include-comments.enabled: true
  # (Optional) Assign unbounded chunks first to prevent possible TaskManager out-of-memory errors.
  scan.incremental.snapshot.unbounded-chunk-first.enabled: true
  # (Optional) Enable parse filtering to accelerate reads.
  scan.only.deserialize.captured.tables.changelog.enabled: true


sink:
  type: maxcompute
  name: MaxComputeSink
  access-id: ${your_accessId}
  access-key: ${your_accessKey}
  endpoint: ${your_maxcompute_endpoint}
  project: ${your_project}
  buckets-num: 8

pipeline:
  name: MySQL to MaxCompute Pipeline

Synchronize an entire database and replace database and table names

In addition to whole-database synchronization, you can add a route module to replace database names and table names in a unified way. The following example shows the configuration:

source:
  type: mysql
  name: MySQL Source
  hostname: <yourHostname>
  port: 3306
  username: flink
  password: ${secret_values.password}
  tables: test_db.\.*
  server-id: 5401-5499
  # (Optional) Synchronize the data of tables created in the incremental phase.
  scan.binlog.newly-added-table.enabled: true
  # (Optional) Synchronize table comments and column comments.
  include-comments.enabled: true
  # (Optional) Assign unbounded chunks first to prevent possible TaskManager out-of-memory errors.
  scan.incremental.snapshot.unbounded-chunk-first.enabled: true
  # (Optional) Enable parse filtering to accelerate reads.
  scan.only.deserialize.captured.tables.changelog.enabled: true


sink:
  type: maxcompute
  name: MaxComputeSink
  access-id: ${your_accessId}
  access-key: ${your_accessKey}
  endpoint: ${your_maxcompute_endpoint}
  project: ${your_project}
  buckets-num: 8
  
route:
  # Synchronize all tables in the MySQL test_db database to the MaxCompute test_db2 database and retain the table names.
  - source-table: test_db.\.*
    sink-table: test_db2.<>
    replace-symbol: <>

pipeline:
  name: MySQL to MaxCompute Pipeline

Exclude specific tables during whole-database synchronization

During whole-database synchronization, to exclude specific tables (such as test tables or tables that cause continuous failovers), use the following configuration:

source:
  type: mysql
  name: MySQL Source
  hostname: <yourHostname>
  port: 3306
  username: flink
  password: ${secret_values.password}
  tables: test_db.\.*
  # Tables matched by this regular expression are not synchronized.
  tables.exclude: test_db.table1
  server-id: 5401-5499
  # (Optional) Synchronize the data of tables created in the incremental phase.
  scan.binlog.newly-added-table.enabled: true
  # (Optional) Synchronize table comments and column comments.
  include-comments.enabled: true
  # (Optional) Assign unbounded chunks first to prevent possible TaskManager out-of-memory errors.
  scan.incremental.snapshot.unbounded-chunk-first.enabled: true
  # (Optional) Enable parse filtering to accelerate reads.
  scan.only.deserialize.captured.tables.changelog.enabled: true

sink:
  type: maxcompute
  name: MaxComputeSink
  access-id: ${your_accessId}
  access-key: ${your_accessKey}
  endpoint: ${your_maxcompute_endpoint}
  project: ${your_project}
  buckets-num: 8

pipeline:
  name: MySQL to MaxCompute Pipeline

Merge sharded tables

To write data from multiple sharded tables to a single downstream table, use the following configuration template:

source:
  type: mysql
  name: MySQL Source
  hostname: <yourHostname>
  port: 3306
  username: flink
  password: ${secret_values.password}
  tables: test_db.user\.*
  server-id: 5401-5499
  # (Optional) Synchronize the data of tables created in the incremental phase.
  scan.binlog.newly-added-table.enabled: true
  # (Optional) Synchronize table comments and column comments.
  include-comments.enabled: true
  # (Optional) Assign unbounded chunks first to prevent possible TaskManager out-of-memory errors.
  scan.incremental.snapshot.unbounded-chunk-first.enabled: true
  # (Optional) Enable parse filtering to accelerate reads.
  scan.only.deserialize.captured.tables.changelog.enabled: true


sink:
  type: maxcompute
  name: MaxComputeSink
  access-id: ${your_accessId}
  access-key: ${your_accessKey}
  endpoint: ${your_maxcompute_endpoint}
  project: ${your_project}
  buckets-num: 8
  
route:
  # All sharded tables in MySQL test_db are merged into a single MaxCompute table named test_db.user.
  - source-table: test_db.user\.*
    sink-table: test_db.user

pipeline:
  name: MySQL to MaxCompute Pipeline

Synchronize existing tables after a restart

To synchronize existing tables that are newly added, set scan.newly-added-table.enabled = true and then restart the job.

Important

If the job first sets scan.binlog.newly-added-table.enabled to true to capture new tables, do not restart the job with scan.newly-added-table.enabled = true to capture existing tables. Otherwise, data is sent repeatedly.

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
  # When the job restarts, check the new tables captured by the tables parameter and take a snapshot.
  # This option must be used together with scan.startup.mode: initial.
  scan.newly-added-table.enabled: true
  # (Optional) Synchronize the data of tables created in the incremental phase.
  scan.binlog.newly-added-table.enabled: true
  # (Optional) Synchronize table comments and column comments.
  include-comments.enabled: true
  # (Optional) Assign unbounded chunks first to prevent possible TaskManager out-of-memory errors.
  scan.incremental.snapshot.unbounded-chunk-first.enabled: true
  # (Optional) Enable parse filtering to accelerate reads.
  scan.only.deserialize.captured.tables.changelog.enabled: true


sink:
  type: maxcompute
  name: MaxComputeSink
  access-id: ${your_accessId}
  access-key: ${your_accessKey}
  endpoint: ${your_maxcompute_endpoint}
  project: ${your_project}
  buckets-num: 8

pipeline:
  name: MySQL to MaxCompute Pipeline

Write to a partitioned table

Converts the upstream create_time field of the timestamp type to a date type and uses it as the partition key of the MaxCompute 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
  # (Optional) Synchronize the data of tables created in the incremental phase.
  scan.binlog.newly-added-table.enabled: true
  # (Optional) Synchronize table comments and column comments.
  include-comments.enabled: true
  # (Optional) Assign unbounded chunks first to prevent possible TaskManager out-of-memory errors.
  scan.incremental.snapshot.unbounded-chunk-first.enabled: true
  # (Optional) Enable parse filtering to accelerate reads.
  scan.only.deserialize.captured.tables.changelog.enabled: true

sink:
  type: maxcompute
  name: MaxComputeSink
  access-id: ${your_accessId}
  access-key: ${your_accessKey}
  endpoint: ${your_maxcompute_endpoint}
  project: ${your_project}
  buckets-num: 8
 
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 MaxCompute Pipeline