Fluss YAML connector

Updated at:

You can use the Fluss connector as a sink in YAML-based data ingestion jobs.

Syntax

source:
   type: xxx

sink:
  type: fluss
  name: Fluss Sink
  bootstrap.servers: localhost:9123
  properties.client.security.protocol: SASL
  properties.client.security.sasl.mechanism: PLAIN
  properties.client.security.sasl.username: developer
  properties.client.security.sasl.password: developer-pass


pipeline:
  schema.change.behavior: IGNORE

Schema change

Fluss Server supports adding columns only. Other column operations, such as dropping a column, renaming a column, and changing a column type, are not supported. Use the Flink CDC default setting schema.change.behavior = LENIENT:

  • Rename a column: The event is converted into a change-column-type event and an add-column event. The original column is retained and changed to nullable, and a new column with the new name and a nullable data type is added.

  • Drop a column: The event is converted into a change-column-type event that changes the corresponding field to nullable.

  • Add a column: The add-column event is still sent, but the field type becomes nullable.

Note

This feature is supported only in VVR 11.6 and later.

Configuration

Parameter

Description

Required

Type

Default

Remarks

type

The sink type.

Yes

STRING

None

Set the value to fluss.

name

The sink name.

No

STRING

None

None.

bootstrap.servers

The address of Fluss Server.

Yes

STRING

None

The format is host:port,host:port,host:port. Separate multiple addresses with commas (,).

bucket.key

The bucket key.

No

String

None

Specifies the data distribution policy of each Fluss table. Separate tables with ';' and bucket keys with ','. Format: database1.table1:key1,key2;database1.table2:key3. Data is distributed to buckets based on the hash value of the bucket key. The bucket key must be a subset of the primary key and cannot include the partition key of a primary key table. If a table has a primary key but no bucket key is specified, the bucket key defaults to the primary key excluding the partition key. If a table has no primary key and no bucket key is specified, data is randomly distributed to buckets. The values of bucket.key and bucket.num cannot be changed after the table is created.

bucket.num

The number of buckets of a Fluss table.

No

String

None

The number of buckets of each Fluss table. Separate tables with ';'. Format: database1.table1:4;database1.table2:8. If the number of buckets is not specified for a table, the server-side parameter default.bucket.number is used. The values of bucket.key and bucket.num cannot be changed after the table is created.

properties.table.*

The Fluss table properties.

No

String

None

Passes the parameters supported by Fluss tables to the pipeline. For more information, see Fluss table options.

properties.client.*

The Fluss client parameters.

No

String

None

Passes the parameters supported by the Fluss client to the pipeline. For more information, see Fluss client options.

Type mapping

The following table describes the data type mappings for data ingestion.

CDC type

Fluss type

TINYINT

TINYINT

SMALLINT

SMALLINT

INT

INT

BIGINT

BIGINT

FLOAT

FLOAT

DOUBLE

DOUBLE

DECIMAL(p, s)

DECIMAL(p, s)

BOOLEAN

BOOLEAN

DATE

DATE

TIME

TIME

TIMESTAMP

TIMESTAMP

TIMESTAMP_LTZ

TIMESTAMP_LTZ

CHAR(n)

CHAR(n)

VARCHAR(n)

STRING

ARRAY

ARRAY

MAP

MAP

ROW

ROW

BINARY(n)

Not supported

VARBINARY(N)

Not supported

Code examples

Replace the endpoint, username, and password in the examples with the actual values. Create a data ingestion job in the development console of Realtime Compute for Apache Flink, paste the YAML code, and then deploy and start the job. You can set the parallelism in the job configurations.

Synchronize data from MySQL to Fluss

Prepare the source as described in MySQL YAML connector, and then run the following SQL statements in MySQL. Use a test database name that is not in use.

CREATE DATABASE fluss_demo;

CREATE TABLE fluss_demo.orders (
    order_id BIGINT NOT NULL,
    customer_id BIGINT NOT NULL,
    amount DECIMAL(12, 2) NOT NULL,
    status VARCHAR(16) NOT NULL,
    PRIMARY KEY (order_id)
);

INSERT INTO fluss_demo.orders VALUES
    (1001, 101, 100.50, 'CREATED'),
    (1002, 102, 80.25, 'PAID'),
    (1003, 101, 60.25, 'PAID'),
    (1004, 101, 39.25, 'PAID'),
    (1005, 102, 19.75, 'CREATED'),
    (1006, 103, 50.50, 'PAID');

The following job synchronizes the full data of the orders table and the subsequent binary log changes to Fluss, and retains the source database name, table name, and primary key. The server-id range must not be used by other replication clients, and the number of IDs must be no less than the source parallelism.

source:
  type: mysql
  name: MySQL Orders Source
  hostname: <mysql-host>
  port: 3306
  username: <mysql-cdc-user>
  password: <mysql-cdc-password>
  tables: fluss_demo.orders
  server-id: 5401-5404
  # Uncomment the next line when binary log parsing becomes a bottleneck and CPU resources are sufficient.
  # scan.parallel-deserialize-changelog.enabled: true
  # For the full synchronization phase of large tables, you can enable the following experimental option before the first startup to prioritize unbounded chunks.
  # scan.incremental.snapshot.unbounded-chunk-first.enabled: true

sink:
  type: fluss
  name: Fluss Orders Sink
  bootstrap.servers: <fluss-bootstrap-host:port>
  bucket.num: fluss_demo.orders:4
  properties.client.security.protocol: SASL
  properties.client.security.sasl.mechanism: PLAIN
  properties.client.security.sasl.username: <fluss-user>
  properties.client.security.sasl.password: <fluss-password>

pipeline:
  schema.change.behavior: LENIENT

After the job starts, the fluss_demo.orders table is created in Fluss. If you change an order amount or delete an order in MySQL, the change is synchronized to the corresponding Fluss table.

Write Kafka JSON data to a Fluss primary key table

Create a users topic in Kafka, and then write the following two JSON messages. Write one message per line.

{"id":1001,"name":"Alice","age":28}
{"id":1002,"name":"Bob","age":32}

The following job reads data from the earliest offset of the topic, uses transform to specify id as the primary key, and uses route to set the sink table to fluss_demo.users. Authentication is not enabled for Kafka in this example. If authentication is enabled, configure the authentication parameters as described in Kafka YAML connector.

source:
  type: kafka
  name: Kafka Users Source
  properties.bootstrap.servers: <kafka-bootstrap-host:port>
  topic: users
  scan.startup.mode: earliest-offset
  value.format: json

sink:
  type: fluss
  name: Fluss Users Sink
  bootstrap.servers: <fluss-bootstrap-host:port>
  properties.client.security.protocol: SASL
  properties.client.security.sasl.mechanism: PLAIN
  properties.client.security.sasl.username: <fluss-user>
  properties.client.security.sasl.password: <fluss-password>

transform:
  - source-table: users
    projection: "*"
    primary-keys: id

route:
  - source-table: users
    sink-table: fluss_demo.users

pipeline:
  schema.change.behavior: LENIENT

Write the following message to the users topic. In the Fluss table, the record whose id is 1001 is updated to age = 29, and the record whose id is 1002 remains unchanged.

{"id":1001,"name":"Alice","age":29}