Supported cluster macros inside table function 'cluster'

This commit is contained in:
Vadim Volodin 2021-07-28 15:33:40 +03:00 committed by Vadim Volodin
parent feeb278b65
commit 918a4e8ab3
4 changed files with 9 additions and 2 deletions

View File

@ -12,6 +12,7 @@
#include <Interpreters/IdentifierSemantic.h> #include <Interpreters/IdentifierSemantic.h>
#include <Common/typeid_cast.h> #include <Common/typeid_cast.h>
#include <Common/parseRemoteDescription.h> #include <Common/parseRemoteDescription.h>
#include <Common/Macros.h>
#include <TableFunctions/TableFunctionFactory.h> #include <TableFunctions/TableFunctionFactory.h>
#include <Core/Defines.h> #include <Core/Defines.h>
#include <common/range.h> #include <common/range.h>
@ -156,10 +157,11 @@ void TableFunctionRemote::parseArguments(const ASTPtr & ast_function, ContextPtr
if (!cluster_name.empty()) if (!cluster_name.empty())
{ {
/// Use an existing cluster from the main config /// Use an existing cluster from the main config
String cluster_name_expanded = context->getMacros()->expand(cluster_name);
if (name != "clusterAllReplicas") if (name != "clusterAllReplicas")
cluster = context->getCluster(cluster_name); cluster = context->getCluster(cluster_name_expanded);
else else
cluster = context->getCluster(cluster_name)->getClusterWithReplicasAsShards(context->getSettings()); cluster = context->getCluster(cluster_name_expanded)->getClusterWithReplicasAsShards(context->getSettings());
} }
else else
{ {

View File

@ -1,6 +1,7 @@
<yandex> <yandex>
<macros> <macros>
<test>Hello, world!</test> <test>Hello, world!</test>
<default_cluster_macro>test_shard_localhost</default_cluster_macro>
<shard>s1</shard> <shard>s1</shard>
<replica>r1</replica> <replica>r1</replica>
<default_path_test>/clickhouse/tables/{database}/{shard}/</default_path_test> <default_path_test>/clickhouse/tables/{database}/{shard}/</default_path_test>

View File

@ -0,0 +1,2 @@
SELECT _shard_num FROM cluster("{default_cluster_macro}", system.one);
SELECT _shard_num FROM clusterAllReplicas("{default_cluster_macro}", system.one);