Class ClickHouseIO
java.lang.Object
org.apache.beam.sdk.io.clickhouse.ClickHouseIO
An IO to write to ClickHouse.
Writing to ClickHouse
To write to ClickHouse, use write(String, String)
, which writes elements
from input PCollection
. It's required that your ClickHouse cluster already has table you
are going to insert into.
pipeline
.apply(...)
.apply(
ClickHouseIO.<POJO>write("jdbc:clickhouse:localhost:8123/default", "my_table"));
Optionally, you can provide connection settings, for instance, specify insert block size with
ClickHouseIO.Write.withMaxInsertBlockSize(long)
, or configure number of retries with ClickHouseIO.Write.withMaxRetries(int)
.
Deduplication
Deduplication is performed by ClickHouse if inserting to ReplicatedMergeTree or Distributed table on top of ReplicatedMergeTree. Without replication, inserting into regular MergeTree can produce duplicates, if insert fails, and then successfully retries. However, each block is inserted atomically, and you can configure block size withClickHouseIO.Write.withMaxInsertBlockSize(long)
.
Deduplication is performed using checksums of inserted blocks.
Mapping between Beam and ClickHouse types
Nested rows should be unnested using Select.flattenedSchema()
. Type casting should be
done using Cast
before ClickHouseIO
.
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic TableSchema
getTableSchema
(String jdbcUrl, String table) ReturnsTableSchema
for a given table.static <T> ClickHouseIO.Write
<T>
-
Field Details
-
DEFAULT_MAX_INSERT_BLOCK_SIZE
public static final long DEFAULT_MAX_INSERT_BLOCK_SIZE- See Also:
-
DEFAULT_MAX_RETRIES
public static final int DEFAULT_MAX_RETRIES- See Also:
-
DEFAULT_MAX_CUMULATIVE_BACKOFF
-
DEFAULT_INITIAL_BACKOFF
-
-
Constructor Details
-
ClickHouseIO
public ClickHouseIO()
-
-
Method Details
-
write
-
getTableSchema
ReturnsTableSchema
for a given table.- Parameters:
jdbcUrl
- jdbc connection urltable
- table name- Returns:
- table schema
-