StarRocks sink connector

Support These Engines

Spark
Flink
SeaTunnel Zeta

Key Features

Description

Used to send data to StarRocks. Both support streaming and batch mode. The internal implementation of StarRocks sink connector is cached and imported by stream load in batches.

Sink Options

Name Type Required Default Description
nodeUrls list yes - StarRocks cluster address, the format is ["fe_ip:fe_http_port", ...]
base-url string yes - The JDBC URL like jdbc:mysql://localhost:9030/ or jdbc:mysql://localhost:9030 or jdbc:mysql://localhost:9030/db
username string yes - StarRocks user username
password string yes - StarRocks user password
database string yes - The name of StarRocks database
table string no - The name of StarRocks table, If not set, the table name will be the name of the upstream table
labelPrefix string no - The prefix of StarRocks stream load label
batch_max_rows long no 1024 For batch writing, when the number of buffers reaches the number of batch_max_rows or the byte size of batch_max_bytes or the time reaches checkpoint.interval, the data will be flushed into the StarRocks
batch_max_bytes int no 5 1024 1024 For batch writing, when the number of buffers reaches the number of batch_max_rows or the byte size of batch_max_bytes or the time reaches checkpoint.interval, the data will be flushed into the StarRocks
max_retries int no - The number of retries to flush failed
retry_backoff_multiplier_ms int no - Using as a multiplier for generating the next delay for backoff
max_retry_backoff_ms int no - The amount of time to wait before attempting to retry a request to StarRocks
enable_upsert_delete boolean no false Whether to enable upsert/delete, only supports PrimaryKey model.
save_mode_create_template string no see below see below
starrocks.config map no - The parameter of the stream load data_desc
http_socket_timeout_ms int no 180000 Set http socket timeout, default is 3 minutes.
schema_save_mode Enum no CREATE_SCHEMA_WHEN_NOT_EXIST Before the synchronous task is turned on, different treatment schemes are selected for the existing surface structure of the target side.
data_save_mode Enum no APPEND_DATA Before the synchronous task is turned on, different processing schemes are selected for data existing data on the target side.
custom_sql String no - When data_save_mode selects CUSTOM_PROCESSING, you should fill in the CUSTOM_SQL parameter. This parameter usually fills in a SQL that can be executed. SQL will be executed before synchronization tasks.

save_mode_create_template

We use templates to automatically create starrocks tables, which will create corresponding table creation statements based on the type of upstream data and schema type, and the default template can be modified according to the situation. Only work on multi-table mode at now.

Default template:

  1. CREATE TABLE IF NOT EXISTS `${database}`.`${table_name}` (
  2. ${rowtype_primary_key},
  3. ${rowtype_fields}
  4. ) ENGINE=OLAP
  5. PRIMARY KEY (${rowtype_primary_key})
  6. DISTRIBUTED BY HASH (${rowtype_primary_key})PROPERTIES (
  7. "replication_num" = "1"
  8. )

If a custom field is filled in the template, such as adding an id field

  1. CREATE TABLE IF NOT EXISTS `${database}`.`${table_name}`
  2. (
  3. id,
  4. ${rowtype_fields}
  5. ) ENGINE = OLAP DISTRIBUTED BY HASH (${rowtype_primary_key})
  6. PROPERTIES
  7. (
  8. "replication_num" = "1"
  9. );

The connector will automatically obtain the corresponding type from the upstream to complete the filling, and remove the id field from rowtype_fields. This method can be used to customize the modification of field types and attributes.

You can use the following placeholders

  • database: Used to get the database in the upstream schema
  • table_name: Used to get the table name in the upstream schema
  • rowtype_fields: Used to get all the fields in the upstream schema, we will automatically map to the field description of StarRocks
  • rowtype_primary_key: Used to get the primary key in the upstream schema (maybe a list)
  • rowtype_unique_key: Used to get the unique key in the upstream schema (maybe a list)

table [string]

Use database and this table-name auto-generate sql and receive upstream input datas write to database.

This option is mutually exclusive with query and has a higher priority.

The table parameter can fill in the name of an unwilling table, which will eventually be used as the table name of the creation table, and supports variables (${table_name}, ${schema_name}). Replacement rules: ${schema_name} will replace the SCHEMA name passed to the target side, and ${table_name} will replace the name of the table passed to the table at the target side.

for example:

  1. test${schema_name}${table_name}_test
  2. sink_sinktable
  3. ss_${table_name}

schema_save_mode[Enum]

Before the synchronous task is turned on, different treatment schemes are selected for the existing surface structure of the target side.
Option introduction:
RECREATE_SCHEMA :Will create when the table does not exist, delete and rebuild when the table is saved
CREATE_SCHEMA_WHEN_NOT_EXIST :Will Created when the table does not exist, skipped when the table is saved
ERROR_WHEN_SCHEMA_NOT_EXIST :Error will be reported when the table does not exist

data_save_mode[Enum]

Before the synchronous task is turned on, different processing schemes are selected for data existing data on the target side.
Option introduction:
DROP_DATA: Preserve database structure and delete data
APPEND_DATA:Preserve database structure, preserve data
CUSTOM_PROCESSING:User defined processing
ERROR_WHEN_DATA_EXISTS:When there is data, an error is reported

custom_sql[String]

When data_save_mode selects CUSTOM_PROCESSING, you should fill in the CUSTOM_SQL parameter. This parameter usually fills in a SQL that can be executed. SQL will be executed before synchronization tasks.

Data Type Mapping

StarRocks Data type SeaTunnel Data type
BOOLEAN BOOLEAN
TINYINT TINYINT
SMALLINT SMALLINT
INT INT
BIGINT BIGINT
FLOAT FLOAT
DOUBLE DOUBLE
DECIMAL DECIMAL
DATE STRING
TIME STRING
DATETIME STRING
STRING STRING
ARRAY STRING
MAP STRING
BYTES STRING

Supported import data formats

The supported formats include CSV and JSON

Task Example

Simple:

The following example describes writing multiple data types to StarRocks, and users need to create corresponding tables downstream

  1. env {
  2. parallelism = 1
  3. job.mode = "BATCH"
  4. checkpoint.interval = 10000
  5. }
  6. source {
  7. FakeSource {
  8. row.num = 10
  9. map.size = 10
  10. array.size = 10
  11. bytes.length = 10
  12. string.length = 10
  13. schema = {
  14. fields {
  15. c_map = "map<string, array<int>>"
  16. c_array = "array<int>"
  17. c_string = string
  18. c_boolean = boolean
  19. c_tinyint = tinyint
  20. c_smallint = smallint
  21. c_int = int
  22. c_bigint = bigint
  23. c_float = float
  24. c_double = double
  25. c_decimal = "decimal(16, 1)"
  26. c_null = "null"
  27. c_bytes = bytes
  28. c_date = date
  29. c_timestamp = timestamp
  30. }
  31. }
  32. }
  33. }
  34. sink {
  35. StarRocks {
  36. nodeUrls = ["e2e_starRocksdb:8030"]
  37. username = root
  38. password = ""
  39. database = "test"
  40. table = "e2e_table_sink"
  41. batch_max_rows = 10
  42. starrocks.config = {
  43. format = "JSON"
  44. strip_outer_array = true
  45. }
  46. }
  47. }

Support write cdc changelog event(INSERT/UPDATE/DELETE)

  1. sink {
  2. StarRocks {
  3. nodeUrls = ["e2e_starRocksdb:8030"]
  4. username = root
  5. password = ""
  6. database = "test"
  7. table = "e2e_table_sink"
  8. ...
  9. // Support upsert/delete event synchronization (enable_upsert_delete=true), only supports PrimaryKey model.
  10. enable_upsert_delete = true
  11. }
  12. }

Use JSON format to import data

  1. sink {
  2. StarRocks {
  3. nodeUrls = ["e2e_starRocksdb:8030"]
  4. username = root
  5. password = ""
  6. database = "test"
  7. table = "e2e_table_sink"
  8. batch_max_rows = 10
  9. starrocks.config = {
  10. format = "JSON"
  11. strip_outer_array = true
  12. }
  13. }
  14. }

Use CSV format to import data

  1. sink {
  2. StarRocks {
  3. nodeUrls = ["e2e_starRocksdb:8030"]
  4. username = root
  5. password = ""
  6. database = "test"
  7. table = "e2e_table_sink"
  8. batch_max_rows = 10
  9. starrocks.config = {
  10. format = "CSV"
  11. column_separator = "\\x01"
  12. row_delimiter = "\\x02"
  13. }
  14. }
  15. }

Use save_mode function

  1. sink {
  2. StarRocks {
  3. nodeUrls = ["e2e_starRocksdb:8030"]
  4. username = root
  5. password = ""
  6. database = "test"
  7. table = "test_${schema_name}_${table_name}"
  8. schema_save_mode = "CREATE_SCHEMA_WHEN_NOT_EXIST"
  9. data_save_mode="APPEND_DATA"
  10. batch_max_rows = 10
  11. starrocks.config = {
  12. format = "CSV"
  13. column_separator = "\\x01"
  14. row_delimiter = "\\x02"
  15. }
  16. }
  17. }

Changelog

next version

  • Add StarRocks Sink Connector
  • [Improve] Change Connector Custom Config Prefix To Map 3719
  • [Feature] Support write cdc changelog event(INSERT/UPDATE/DELETE) 3865