Targets
ClickHouse
Load into a self-hosted ClickHouse server: rows sent as Arrow over HTTP into a staging table, then published by swapping in whole tables or partitions.
A ClickHouse target loads into one self-hosted ClickHouse server over its HTTP interface. Each batch goes as Arrow into a staging table, and reaches the table only when the load publishes it by swapping in a whole table or whole partitions. ClickHouse reads Parquet files in S3 itself.
Connection
Section titled “Connection”[connections.serving]kind = "clickhouse"host = "clickhouse.example.com"password = "${ENV:CLICKHOUSE_PASSWORD}"# port = 8123# user = "default"# secure = true
[targets.serving]connection = "serving"loader_schema = "raw"| Key | Meaning |
|---|---|
host |
The server’s host name. Required. |
port |
The HTTP port. Default: 8123, or 8443 with secure = true. |
user |
The user SQLLoad signs in as. Default: default. |
password |
The user’s password. Use ${ENV:NAME}. |
secure |
true for HTTPS. Default: false. |
loader_schema is the ClickHouse database tables load into; a source’s destination_schema
overrides it. plan refuses a database key, as ClickHouse has no level above databases.
sqlload apply creates the database when it doesn’t exist. sqlload debug checks the connection
and prints the user, the server’s version and its time zone.
Permissions
Section titled “Permissions”The user needs grants in the target’s databases to create databases and tables, insert, move
partitions (ATTACH, REPLACE and DROP PARTITION), delete rows (DELETE FROM or
ALTER TABLE ... DELETE), exchange, rename and drop tables, and read with the s3 table function.
Its profile must let it set settings per query: not readonly = 1, and no constraint fixing
async_insert on.
Table layout
Section titled “Table layout”These settings lay out a table SQLLoad creates, on a source for all its tables or on one table. They use SQLBuild’s names:
[sources.app.tables."public.orders"]description = "Orders, one row per order."partition_by = "toYYYYMM(updated_at)"order_by = ["customer_id", "order_id"]# primary_key = ["customer_id"]# table_settings = { index_granularity = 4096 }| Key | Default | Meaning |
|---|---|---|
engine |
MergeTree |
The table engine, with its arguments. Only MergeTree-family engines on one server. ClickHouse refuses a Nullable version column, so give ReplacingMergeTree no version argument. |
order_by |
a merge table’s unique_key; another table’s unique_key if it sets one, else the source’s primary key; else unsorted |
The sorting key: an expression or a list of them. |
partition_by |
none | The partitioning expression. |
primary_key |
none | The primary key, a prefix of order_by. |
table_settings |
none | Table settings by name. A table’s settings are added to its source’s, the table’s value winning. |
Every loaded column is Nullable (other than a native(...) pin), so a table with a key gets
allow_nullable_key = 1 unless table_settings sets it. plan refuses BigQuery’s cluster_by,
and targets other than ClickHouse and
BigQuery refuse these settings.
The layout applies only when SQLLoad creates a table; --reload keeps it. To lay a table out again,
drop it and load. ClickHouse can’t change the type of a sorting or partition key column, so a key
column whose source type widens fails the load.
How rows arrive
Section titled “How rows arrive”Rows go as zstd-compressed Arrow into a staging table (a build table for replace), and each
insert writes its rows before it returns. Each publish is one swap, atomic in an Atomic database,
ClickHouse’s default: a load stopped at any point leaves the table as it was or fully published,
and the next run converges. In an Ordinary database the swap is a RENAME TABLE, which isn’t
atomic: readers can briefly find no table.
Rows never arrive by INSERT into the table, so materialized views on it see none of them. Build
them from the table instead.
Files ClickHouse reads itself
Section titled “Files ClickHouse reads itself”A files source of Parquet in S3 skips SQLLoad: ClickHouse reads each file with s3() into the
staging table, and plan shows the route as ClickHouse reads directly from s3://....
- ClickHouse signs its reads with the credentials SQLLoad reads S3 with, sent as query parameters,
never in the SQL. With
AWS_SKIP_SIGNATURE=truethe reads are unsigned. - The server must reach the bucket, the S3 connection’s
endpointorAWS_ENDPOINT_URL_S3. - A signed read’s statement must stay under ClickHouse’s
http_max_field_value_size: 128 KiB by default, about 1,800 columns. - A folder value that doesn’t fit its type fails the load, and a batch loads only if ClickHouse writes as many rows as the files’ footers hold.
SQLLoad reads the files itself when ClickHouse wouldn’t load them exactly: formats other than Parquet, local folders, masked columns, a column loaded as another type than the files hold, nanosecond or epoch timestamps, times of day, or a path that reads as a glob.
A Snowflake source with a stage url in S3 skips SQLLoad too; see
Databricks and ClickHouse read the files themselves.
Write strategies
Section titled “Write strategies”| Strategy | Publishes |
|---|---|
append |
Attaches the new rows’ partition to the table. Rows in several partitions go into a copy of the table, which is exchanged in. |
merge |
Rewrites each partition holding a matched key or a new row. |
delete_insert |
Rewrites each partition holding the cursor range it read. |
replace |
Builds a new table and swaps it in with EXCHANGE TABLES. --reload does the same. |
merge matches rows on unique_key exactly, so readers need no FINAL. It replaces whole rows,
so a column dropped at the source is NULL on the rows it updates.
A publish rewrites the partitions it touches, so partition large tables by the column new rows
arrive on; an unpartitioned table is one partition. On 25.5 and later, unless the user’s profile
pins lightweight_delete_mode, it deletes with a lightweight DELETE: the rows it removes stay
counted in system.parts.rows and system.tables.total_rows, though hidden from readers, until
ClickHouse next merges the parts. Where a lightweight DELETE is refused, as on a table with
projections, it uses ALTER TABLE ... DELETE, which rewrites the touched parts.
append, merge and delete_insert publish once per run, even when they read in windows
(batch_size) or in cursor order, so readers never see part of
a run. A run stopped partway publishes nothing after its last commit; split a long backfill into
several runs with --end-cursor. Exceptions:
- A
mergealso commits at the end of the window or batch in which 10 million rows are waiting; keepbatch_sizewindows well under that. Withon_duplicate_keys = "fail"it commits each batch, and without a cursor about every 1 GB. Within a run it keeps the last row read of each key, or the newest bynewest_by. - A files source commits each batch of partitions as it goes.
SQLLoad must be the only writer of the tables it loads. Rows another writer adds while a load
publishes can be lost, and the next publish undoes or refuses a lightweight UPDATE run on the
table.
Rows are sorted by the partition key on the server, making about one part per partition; that
takes server memory, and where it runs out they’re inserted unsorted, as more parts. replace and
--reload into a partitioned table write each row twice on the server to sort it.
Every column is Nullable, as plan shows: int is Nullable(Int64).
| Type | ClickHouse |
|---|---|
bool |
Bool |
smallint |
Int16 |
int |
Int64 |
decimal(p,s) |
Decimal(p, s) |
float |
Float64 |
text |
String |
varchar(n) |
String ¹ |
date |
Date32 ¹ |
time |
String ¹ |
timestamp_tz |
DateTime64(6, 'UTC') ¹ |
timestamp_ntz |
DateTime64(6) ¹ |
json |
String ¹ |
uuid |
UUID |
binary |
String |
¹ Held with a loss: varchar lengths aren’t enforced; time and json are stored as text;
timestamp_tz is a UTC instant without its offset; timestamp_ntz is shown in the server’s time
zone. date and both timestamps hold values from 1900 to 2299, and a value outside them fails the
load.
Pin native("JSON") or native("LowCardinality(String)") on a text column in columns to use
those types, exactly as written.
plan reports an existing table’s narrower types (Int32, UInt16, Float32, Date,
DateTime, DateTime64(3)) as incompatible, since they would wrap or cut wider values silently.
Limitations
Section titled “Limitations”- One server only: clusters, replicated tables and distributed tables aren’t supported.
- ClickHouse Cloud is untested.
- Load each table from one
sqlloadprocess at a time. copy_to_internal_stageis for Snowflake and is refused here.- A Postgres CDC source can’t load into ClickHouse;
planrefuses it.
Tested
Section titled “Tested”Container tests run against ClickHouse 25.3, 25.8 and 26.10 and an S3-compatible store. They load
Postgres tables repeatedly under every write strategy: layouts, every portable type, merge moving
a row between partitions without FINAL, delete_insert emptying a partition, replace by
exchange and by renames, a new source column, and no staging tables left behind. ClickHouse reads
Parquet in S3 itself. Loads and file reads stopped at every statement, then run again, never leave
a table half published.