ClickHouse/flink-connector-clickhouse

Official Apache Flink connector for ClickHouse

29

stars

356

commits

Java

primary language

Sep 8, 2026

updated

clickhouse
flink
flink-streaming
java

README

ClickHouse Flink Connector

Table of Contents

About The Project

This is a repo of ClickHouse official Apache Flink Connector supported by the ClickHouse team. The connector supports two main Apache Flink APIs:

  • DataStreamAPI
  • Table API (This feature is not implemented yet and is planned for a future release)
VersionDependencyClickHouse Client VersionRequired Java
latestflink-connector-clickhouse-2.0.00.9.5Java 17+
2.0.1flink-connector-clickhouse-2.0.00.9.5Java 17+
2.0.0flink-connector-clickhouse-2.0.00.9.5Java 17+
1.20.2flink-connector-clickhouse-1.170.9.5Java 11+
1.19.3flink-connector-clickhouse-1.170.9.5Java 11+
1.18.1flink-connector-clickhouse-1.170.9.5Java 11+
1.17.2flink-connector-clickhouse-1.170.9.5Java 11+

Installation

Maven

<dependency>
    <groupId>com.clickhouse.flink</groupId>
    <artifactId>flink-connector-clickhouse-2.0.0</artifactId>
    <version>0.2.0</version>
    <classifier>all</classifier>
</dependency>

Maven

<dependency>
    <groupId>com.clickhouse.flink</groupId>
    <artifactId>flink-connector-clickhouse-1.17</artifactId>
    <version>0.2.0</version>
    <classifier>all</classifier>
</dependency>

DataStream API

Snippet

Configure ClickHouseClient

ClickHouseClientConfig clickHouseClientConfig = new ClickHouseClientConfig(url, username, password, database, tableName);

If you are planning to insert RAW CSV data as is

Create a ClickHouseConvertor

ClickHouseConvertor<String> convertorString = new ClickHouseConvertor<>(String.class);

Build the sink (optional knobs have sensible defaults — set only what you need):

ClickHouseAsyncSink<String> csvSink = ClickHouseAsyncSink.<String>builder()
        .setElementConverter(convertorString)
        .setClickHouseClientConfig(clickHouseClientConfig)
        .setClickHouseFormat(ClickHouseFormat.CSV)
        .setMaxBatchSize(MAX_BATCH_SIZE)
        .setMaxInFlightRequests(MAX_IN_FLIGHT_REQUESTS)
        .setMaxBufferedRequests(MAX_BUFFERED_REQUESTS)
        .setMaxBatchSizeInBytes(MAX_BATCH_SIZE_IN_BYTES)
        .setMaxTimeInBufferMS(MAX_TIME_IN_BUFFER_MS)
        .setMaxRecordSizeInBytes(MAX_RECORD_SIZE_IN_BYTES)
        .build();

Finally, connect your DataStream to the sink.

data.sinkTo(csvSink);

More examples and snippets can be found in our tests flink-connector-clickhouse-1.17 and flink-connector-clickhouse-2.0.0

Example

We have created maven based example for easy start with ClickHouse Sink Different versions for Flink

Java (Maven)

Scala (sbt)

For more detailed instructions, see the Example Guide

Table API

Table API is planned for a future release. This section will be updated once available.

Snippet

Planned for a future release — this section will provide a usage snippet for configuring the Table API.

Example

Planned for a future release — a complete end-to-end example will be added once the Table API becomes available.

Supported ClickHouse Types

Java TypeClickHouse TypeSupportedSerialize Method
byte/ByteInt8DataWriter.writeInt8
short/ShortInt16DataWriter.writeInt16
int/IntegerInt32DataWriter.writeInt32
long/LongInt64DataWriter.writeInt64
BigIntegerInt128DataWriter.writeInt124
BigIntegerInt256DataWriter.writeInt256
short/ShortUInt8DataWriter.writeUInt8
int/IntegerUInt8DataWriter.writeUInt8
int/IntegerUInt16DataWriter.writeUInt16
long/LongUInt32DataWriter.writeUInt32
long/LongUInt64DataWriter.writeUInt64
BigIntegerUInt64DataWriter.writeUInt64
BigIntegerUInt128DataWriter.writeUInt128
BigIntegerUInt256DataWriter.writeUInt256
BigDecimalDecimalDataWriter.writeDecimal
BigDecimalDecimal32DataWriter.writeDecimal
BigDecimalDecimal64DataWriter.writeDecimal
BigDecimalDecimal128DataWriter.writeDecimal
BigDecimalDecimal256DataWriter.writeDecimal
float/FloatFloatDataWriter.writeFloat32
double/DoubleDoubleDataWriter.writeFloat64
boolean/BooleanBooleanDataWriter.writeBoolean
StringStringDataWriter.writeString
StringFixedStringDataWriter.writeFixedString
LocalDateDateDataWriter.writeDate
LocalDateDate32DataWriter.writeDate32
LocalDateTimeDateTimeDataWriter.writeDateTime
ZonedDateTimeDateTimeDataWriter.writeDateTime
LocalDateTimeDateTime64DataWriter.writeDateTime64
ZonedDateTimeDateTime64DataWriter.writeDateTime64
int/IntegerTimeN/A
long/LongTime64N/A
byte/ByteEnum8DataWriter.writeInt8
int/IntegerEnum16DataWriter.writeInt16
java.util.UUIDUUIDDataWriter.writeIntUUID
StringJSONDataWriter.writeJSON
ArrayArrayDataWriter.writeArray
Map<K,V>Map<K,V>DataWriter.writeMap
Tuple<Type,..>Tuple<T1,T2,..>DataWriter.writeTuple
ObjectVariantN/A
(inner type T)SimpleAggregateFunction(f, T)writer for inner type T
  • A ZoneId must also be provided when performing date operations.
  • Precision and scale must also be provided when performing decimal operations.
  • To use JSON type as a string, you need to enable enableJsonSupportAsString in ClickHouseClientConfig .
  • SimpleAggregateFunction(f, T) is wire-encoded exactly as its inner type T, so bind the Java value for T and ignore the aggregate function f. Any T supported above works, including Nullable, LowCardinality, Decimal, Array, Map and Tuple.

Configuration Options

Client configuration

ParametersDescriptionDefault Value
urlfully qualified URLN/A
usernameClickHouse database usernameN/A
passwordClickHouse database passwordN/A
databaseClickHouse database nameN/A
tableClickHouse table nameN/A

Sink configuration

Our Sink is built on top of Flink’s AsyncSinkBase

ParametersDescriptionDefault Value
maxBatchSizeMaximum number of records inserted in a single batchN/A
maxInFlightRequestsThe maximum number of in flight requests allowed before the sink applies backpressureN/A
maxBufferedRequestsThe maximum number of records that may be buffered in the sink before backpressure is appliedN/A
maxBatchSizeInBytesThe maximum size (in bytes) a batch may become. All batches sent will be smaller than or equal to this sizeN/A
maxTimeInBufferMSThe maximum time a record may stay in the sink before being flushedN/A
maxRecordSizeInBytesThe maximum record size that the sink will accept, records larger than this will be automatically rejectedN/A

Sink Metrics

Our Sink exposes additional metrics on top of Flink's existing metrics:

MetricDescriptionTypeStatus
numBytesSendTotal number of bytes sent to ClickHouseCounter
numRecordSendTotal number of records sent to ClickHouseCounter
numRequestSubmittedTotal number of requests sent (actual number of flushes performed)Counter
numOfDroppedBatchesTotal number of batches dropped due to non-retryable failuresCounter
numOfDroppedRecordsTotal number of records dropped due to non-retryable failuresCounter
totalBatchRetriesTotal number of batch retries due to retryable failuresCounter
writeLatencyHistogramHistogram of write latency distributionHistogram
writeFailureLatencyHistogramHistogram of write failure latency distributionHistogram
triggeredByMaxBatchSizeCounterSink flushes triggered by reaching maxBatchSizeCounter
triggeredByMaxBatchSizeInBytesCounterSink flushes triggered by reaching maxBatchSizeInBytesCounter
triggeredByMaxTimeInBufferMSCounterSink flushes triggered by reaching maxTimeInBufferMSCounter
actualRecordsPerBatchHistogramHistogram of actual batch size distributionHistogram
actualBytesPerBatchHistogramHistogram of actual bytes per batch distributionHistogram
actualTimeInBufferHistogramHistogram of actual time in buffer before flush distributionHistogram

Limitations

  • Currently the sink does not support exactly-once semantics

Compatibility

  • All projects in this repo are tested with all active LTS versions of ClickHouse.
  • Support policy
  • We recommend upgrading the connector continuously to not miss security fixes and new improvements
    • If you have an issue with migration - create and issue and we will respond!

Contributing

Please see our contributing guide.

Contributors

mzitnik

319 commits

Marais

28 commits

EliFrun

6 commits

ClickHouse/flink-connector-clickhouse

Official Apache Flink connector for ClickHouse

29

stars

356

commits

Java

primary language

Sep 8, 2026

updated

clickhouse
flink
flink-streaming
java

README

ClickHouse Flink Connector

Table of Contents

About The Project

This is a repo of ClickHouse official Apache Flink Connector supported by the ClickHouse team. The connector supports two main Apache Flink APIs:

  • DataStreamAPI
  • Table API (This feature is not implemented yet and is planned for a future release)
VersionDependencyClickHouse Client VersionRequired Java
latestflink-connector-clickhouse-2.0.00.9.5Java 17+
2.0.1flink-connector-clickhouse-2.0.00.9.5Java 17+
2.0.0flink-connector-clickhouse-2.0.00.9.5Java 17+
1.20.2flink-connector-clickhouse-1.170.9.5Java 11+
1.19.3flink-connector-clickhouse-1.170.9.5Java 11+
1.18.1flink-connector-clickhouse-1.170.9.5Java 11+
1.17.2flink-connector-clickhouse-1.170.9.5Java 11+

Installation

Maven

<dependency>
    <groupId>com.clickhouse.flink</groupId>
    <artifactId>flink-connector-clickhouse-2.0.0</artifactId>
    <version>0.2.0</version>
    <classifier>all</classifier>
</dependency>

Maven

<dependency>
    <groupId>com.clickhouse.flink</groupId>
    <artifactId>flink-connector-clickhouse-1.17</artifactId>
    <version>0.2.0</version>
    <classifier>all</classifier>
</dependency>

DataStream API

Snippet

Configure ClickHouseClient

ClickHouseClientConfig clickHouseClientConfig = new ClickHouseClientConfig(url, username, password, database, tableName);

If you are planning to insert RAW CSV data as is

Create a ClickHouseConvertor

ClickHouseConvertor<String> convertorString = new ClickHouseConvertor<>(String.class);

Build the sink (optional knobs have sensible defaults — set only what you need):

ClickHouseAsyncSink<String> csvSink = ClickHouseAsyncSink.<String>builder()
        .setElementConverter(convertorString)
        .setClickHouseClientConfig(clickHouseClientConfig)
        .setClickHouseFormat(ClickHouseFormat.CSV)
        .setMaxBatchSize(MAX_BATCH_SIZE)
        .setMaxInFlightRequests(MAX_IN_FLIGHT_REQUESTS)
        .setMaxBufferedRequests(MAX_BUFFERED_REQUESTS)
        .setMaxBatchSizeInBytes(MAX_BATCH_SIZE_IN_BYTES)
        .setMaxTimeInBufferMS(MAX_TIME_IN_BUFFER_MS)
        .setMaxRecordSizeInBytes(MAX_RECORD_SIZE_IN_BYTES)
        .build();

Finally, connect your DataStream to the sink.

data.sinkTo(csvSink);

More examples and snippets can be found in our tests flink-connector-clickhouse-1.17 and flink-connector-clickhouse-2.0.0

Example

We have created maven based example for easy start with ClickHouse Sink Different versions for Flink

Java (Maven)

Scala (sbt)

For more detailed instructions, see the Example Guide

Table API

Table API is planned for a future release. This section will be updated once available.

Snippet

Planned for a future release — this section will provide a usage snippet for configuring the Table API.

Example

Planned for a future release — a complete end-to-end example will be added once the Table API becomes available.

Supported ClickHouse Types

Java TypeClickHouse TypeSupportedSerialize Method
byte/ByteInt8DataWriter.writeInt8
short/ShortInt16DataWriter.writeInt16
int/IntegerInt32DataWriter.writeInt32
long/LongInt64DataWriter.writeInt64
BigIntegerInt128DataWriter.writeInt124
BigIntegerInt256DataWriter.writeInt256
short/ShortUInt8DataWriter.writeUInt8
int/IntegerUInt8DataWriter.writeUInt8
int/IntegerUInt16DataWriter.writeUInt16
long/LongUInt32DataWriter.writeUInt32
long/LongUInt64DataWriter.writeUInt64
BigIntegerUInt64DataWriter.writeUInt64
BigIntegerUInt128DataWriter.writeUInt128
BigIntegerUInt256DataWriter.writeUInt256
BigDecimalDecimalDataWriter.writeDecimal
BigDecimalDecimal32DataWriter.writeDecimal
BigDecimalDecimal64DataWriter.writeDecimal
BigDecimalDecimal128DataWriter.writeDecimal
BigDecimalDecimal256DataWriter.writeDecimal
float/FloatFloatDataWriter.writeFloat32
double/DoubleDoubleDataWriter.writeFloat64
boolean/BooleanBooleanDataWriter.writeBoolean
StringStringDataWriter.writeString
StringFixedStringDataWriter.writeFixedString
LocalDateDateDataWriter.writeDate
LocalDateDate32DataWriter.writeDate32
LocalDateTimeDateTimeDataWriter.writeDateTime
ZonedDateTimeDateTimeDataWriter.writeDateTime
LocalDateTimeDateTime64DataWriter.writeDateTime64
ZonedDateTimeDateTime64DataWriter.writeDateTime64
int/IntegerTimeN/A
long/LongTime64N/A
byte/ByteEnum8DataWriter.writeInt8
int/IntegerEnum16DataWriter.writeInt16
java.util.UUIDUUIDDataWriter.writeIntUUID
StringJSONDataWriter.writeJSON
ArrayArrayDataWriter.writeArray
Map<K,V>Map<K,V>DataWriter.writeMap
Tuple<Type,..>Tuple<T1,T2,..>DataWriter.writeTuple
ObjectVariantN/A
(inner type T)SimpleAggregateFunction(f, T)writer for inner type T
  • A ZoneId must also be provided when performing date operations.
  • Precision and scale must also be provided when performing decimal operations.
  • To use JSON type as a string, you need to enable enableJsonSupportAsString in ClickHouseClientConfig .
  • SimpleAggregateFunction(f, T) is wire-encoded exactly as its inner type T, so bind the Java value for T and ignore the aggregate function f. Any T supported above works, including Nullable, LowCardinality, Decimal, Array, Map and Tuple.

Configuration Options

Client configuration

ParametersDescriptionDefault Value
urlfully qualified URLN/A
usernameClickHouse database usernameN/A
passwordClickHouse database passwordN/A
databaseClickHouse database nameN/A
tableClickHouse table nameN/A

Sink configuration

Our Sink is built on top of Flink’s AsyncSinkBase

ParametersDescriptionDefault Value
maxBatchSizeMaximum number of records inserted in a single batchN/A
maxInFlightRequestsThe maximum number of in flight requests allowed before the sink applies backpressureN/A
maxBufferedRequestsThe maximum number of records that may be buffered in the sink before backpressure is appliedN/A
maxBatchSizeInBytesThe maximum size (in bytes) a batch may become. All batches sent will be smaller than or equal to this sizeN/A
maxTimeInBufferMSThe maximum time a record may stay in the sink before being flushedN/A
maxRecordSizeInBytesThe maximum record size that the sink will accept, records larger than this will be automatically rejectedN/A

Sink Metrics

Our Sink exposes additional metrics on top of Flink's existing metrics:

MetricDescriptionTypeStatus
numBytesSendTotal number of bytes sent to ClickHouseCounter
numRecordSendTotal number of records sent to ClickHouseCounter
numRequestSubmittedTotal number of requests sent (actual number of flushes performed)Counter
numOfDroppedBatchesTotal number of batches dropped due to non-retryable failuresCounter
numOfDroppedRecordsTotal number of records dropped due to non-retryable failuresCounter
totalBatchRetriesTotal number of batch retries due to retryable failuresCounter
writeLatencyHistogramHistogram of write latency distributionHistogram
writeFailureLatencyHistogramHistogram of write failure latency distributionHistogram
triggeredByMaxBatchSizeCounterSink flushes triggered by reaching maxBatchSizeCounter
triggeredByMaxBatchSizeInBytesCounterSink flushes triggered by reaching maxBatchSizeInBytesCounter
triggeredByMaxTimeInBufferMSCounterSink flushes triggered by reaching maxTimeInBufferMSCounter
actualRecordsPerBatchHistogramHistogram of actual batch size distributionHistogram
actualBytesPerBatchHistogramHistogram of actual bytes per batch distributionHistogram
actualTimeInBufferHistogramHistogram of actual time in buffer before flush distributionHistogram

Limitations

  • Currently the sink does not support exactly-once semantics

Compatibility

  • All projects in this repo are tested with all active LTS versions of ClickHouse.
  • Support policy
  • We recommend upgrading the connector continuously to not miss security fixes and new improvements
    • If you have an issue with migration - create and issue and we will respond!

Contributing

Please see our contributing guide.

Contributors

mzitnik

319 commits

Marais

28 commits

EliFrun

6 commits

Languages

Java

98.8%

Scala

1.2%