ClickHouse
Use ClickHouse when that is already your analytics store. Mfd inserts batches into database.table. A retry can write a batch again, so plan a unique key or a downstream dedup. See Exactly-once delivery.
Before you begin
- A HTTP(S) URL for the ClickHouse service (
https://host:8443). - A database and a user that can insert (and create the table if it does not exist).
export CLICKHOUSE_PASSWORD="change-me"Configure
from mfd import Config, DataSinkClickhouse, EnvRef, Pipeline
cfg = Config.discover()
ch = cfg.data_sink(
"warehouse",
DataSinkClickhouse(
url="https://clickhouse.internal:8443",
database="analytics",
user="mfd",
password=EnvRef("CLICKHOUSE_PASSWORD"),
table="events",
),
)
cfg.pipeline("events", Pipeline(data_source=cfg.get_data_source("sample"), data_sink=ch))
cfg.save()mfd connect data-sink clickhouse \
--pipeline events \
--name warehouse \
--url https://clickhouse.internal:8443 \
--database analytics \
--user mfd \
--password '${CLICKHOUSE_PASSWORD}' \
--table eventsdata_sinks:
warehouse:
Clickhouse:
url: https://clickhouse.internal:8443
database: analytics
user: mfd
password: ${CLICKHOUSE_PASSWORD}
table: eventsOptions
| Key | Type | Required/Default | Description |
|---|---|---|---|
url | URL | Required | ClickHouse HTTP(S) endpoint |
database | string | Not set | Database; omitted uses the server default |
user | string | Not set | User |
password | secret | Not set | Password as ${ENV} |
table | string | Not set | Table name; omitted uses the pipeline namespace |
How data lands
Snapshot batches insert as Apache Parquet over HTTP (INSERT … FORMAT Parquet). That is the only write path. Mfd creates a MergeTree table when table does not exist. Nested columns land as ClickHouse Tuple, Array, and Map (never Nullable(Array/Map/Tuple)); dates as Date32; decimals as Decimal(38, 9). Business-key columns used in ORDER BY are non-nullable.
CDC uses a ReplacingMergeTree(_mfd_version, _mfd_is_deleted) table ordered by the business key. _mfd_version packs the WAL tie as seq (32 bits), ordinal (8 bits), and row (24 bits); a value that does not fit fails closed. Deletes set _mfd_is_deleted. Query with FINAL (or wait for a merge) to see the current row. Do not run CDC against a snapshot MergeTree table. Create a separate table, or drop the snapshot table first.
A retry can write a batch again before merge. Deduplicate on your primary key, or rely on ReplacingMergeTree plus FINAL for CDC.
Troubleshooting
| Symptom | Fix |
|---|---|
| Connection refused | Check url and TLS |
| Authentication failed | Export the password variable in this shell |
| Table missing | Grant CREATE or create the table first |
| ClickHouse CDC requires ReplacingMergeTree | CDC will not write to a snapshot MergeTree table. Use a different table, or drop the snapshot table first. |
