Topic: readings PartitionCount: 6 ReplicationFactor: 2 Configs:
Topic: readings Partition: 0 Leader: 0 Replicas: 0,2 Isr: 0,2
Topic: readings Partition: 1 Leader: 2 Replicas: 2,1 Isr: 2,1
Topic: readings Partition: 2 Leader: 1 Replicas: 1,0 Isr: 1,0
Topic: readings Partition: 3 Leader: 0 Replicas: 0,1 Isr: 0,1
Topic: readings Partition: 4 Leader: 2 Replicas: 2,0 Isr: 2,0
Topic: readings Partition: 5 Leader: 1 Replicas: 1,2 Isr: 1,2
现在 Kafak 准备工作已完成。让我们转向ClickHouse。
ClickHouse Kafka 引擎设置
要将数据从 Kafka 主题读取到 ClickHouse 表,我们需要做三件事:
- 一个目标 MergeTree 表,用于为引入的数据提供主目录
- 一个 Kafka 引擎表,使主题看起来像一个 ClickHouse 表
- 用于自动将数据从 Kafka 移动到目标表的具体化视图
首先,我们将定义目标 MergeTree 表。登录到 ClickHouse 执行以下 SQL
CREATE TABLE readings (
readings_id Int32 Codec(DoubleDelta, LZ4),
time DateTime Codec(DoubleDelta, LZ4),
date ALIAS toDate(time),
temperature Decimal(5,2) Codec(T64, LZ4)
) Engine = MergeTree
PARTITION BY toYYYYMM(time)
ORDER BY (readings_id, time);
接下来,我们需要使用 Kafka 引擎创建一个表来连接主题并读取数据。引擎将使用主题“readings”和消费者组名称“readings consumer_group1”从主机 kafka 的代理读取数据。输入格式为