Integration package
The integration package required to integrate Apache Beam and ClickHouse is maintained and developed under Apache Beam I/O Connectors - an integrations bundle of many popular data storage systems and databases.org.apache.beam.sdk.io.clickhouse.ClickHouseIO implementation located within the Apache Beam repo.
Setup of the Apache Beam ClickHouse package
Package installation
Add the following dependency to your package management framework:ClickHouseIO connector is recommended for use starting from Apache Beam version 2.59.0.
Earlier versions may not fully support the connector’s functionality.
:::
The artifacts could be found in the official maven repository.
Code example
The following example reads a CSV file namedinput.csv as a PCollection, converts it to a Row object (using the defined schema) and inserts it into a local ClickHouse instance using ClickHouseIO:
Supported data types
ClickHouseIO.Write parameters
You can adjust theClickHouseIO.Write configuration with the following setter functions:
Limitations
Please consider the following limitations when using the connector:- As of today, only Sink operation is supported. The connector doesn’t support Source operation.
- ClickHouse performs deduplication when inserting into a
ReplicatedMergeTreeor aDistributedtable built on top of aReplicatedMergeTree. Without replication, inserting into a regular MergeTree can result in duplicates if an insert fails and then successfully retries. However, each block is inserted atomically, and the block size can be configured usingClickHouseIO.Write.withMaxInsertBlockSize(long). Deduplication is achieved by using checksums of the inserted blocks. For more information about deduplication, please visit Deduplication and Deduplicate insertion config. - The connector doesn’t perform any DDL statements; therefore, the target table must exist prior insertion.
Related content
ClickHouseIOclass documentation.Githubrepository of examples clickhouse-beam-connector.