Merge pull request #26913 from PolyProgrammist/table-function-cluster-macros

Supported cluster macros inside table function 'cluster'
This commit is contained in:
tavplubix 2021-07-29 18:43:36 +03:00 committed by GitHub
commit c18c16855a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 9 additions and 2 deletions

View File

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

View File

@ -1,6 +1,7 @@
<yandex>
<macros>
<test>Hello, world!</test>
<default_cluster_macro>test_shard_localhost</default_cluster_macro>
<shard>s1</shard>
<replica>r1</replica>
<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);