clickhouse 中的“宏”是什么,clickhouse 中“宏”的用途是什么?

问题描述

Clickhouse 中的 macros 是什么?

Clickhouse 中 macros 的用例是什么?

<macros>
    <cluster>MyFirstCluster</cluster>
    <replica>chdw1-5</replica>
    <shard>5</shard>
</macros>

config 中每个属性的含义是什么?

在配置中分配每个属性的最佳实践是什么?

解决方法

它们用于复制引擎 ZK 路径。

https://clickhouse.tech/docs/en/engines/table-engines/mergetree-family/replication/#creating-replicated-tables

CREATE TABLE table_name
(
    EventDate DateTime,CounterID UInt32,UserID UInt32,ver UInt16
) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/{layer}-{shard}/table_name','{replica}',ver)
PARTITION BY toYYYYMM(EventDate)
ORDER BY (CounterID,EventDate,intHash32(UserID))
SAMPLE BY intHash32(UserID)

每个 CH 节点都是独立的,不知道集群/分片/复制。

但是 Replicated* 引擎使用 ZK 路径进行复制(以将自己标识为副本)。此 ZK 路径是从宏呈现的。

所以在你的情况下,而不是

ReplicatedReplacingMergeTree('/clickhouse/{cluster}/tables/{shard}/table_name',ver)

实际上宏将被替换。