ClickHouse Cluster Macros

Macro functionality is available as part of ClickHouse for conveniently accessing pre-defined values. Instaclustr leverages this functionality and ships a few useful macros together with all our ClickHouse clusters. An example from a testing cluster is shown below: 

You can retrieve the list of available macros using the select * from system.macros query.  

The macros are defined as part of the configuration files and can be accessed using the getMacro method: 

These macros can also be used as part of any query directly. For example, if one wishes to execute a query on all nodes in a cluster, the cluster macro can be used as such: 

Aside from being used directly, Instaclustr also configured some default values for DDL queries using these macros so that they don’t have to be specified by users explicitly, reducing possibility of human errors in some of the complicated strings. This includes the “default_replica_path” and “default_replica_name” parameters as shown below:

Users can for example create a replicated table using “ENGINE = ReplicatedMergeTree” directly, instead of  

ENGINE = ReplicatedMergeTree( ‘/clickhouse/tables/{shard}/table_name’, ‘{replica}’)”.