From 918a4e8ab305f248fd8b0ab0dadd428ac2847caa Mon Sep 17 00:00:00 2001 From: Vadim Volodin Date: Wed, 28 Jul 2021 15:33:40 +0300 Subject: [PATCH] Supported cluster macros inside table function 'cluster' --- src/TableFunctions/TableFunctionRemote.cpp | 6 ++++-- tests/config/config.d/macros.xml | 1 + .../02000_table_function_cluster_macros.reference | 2 ++ .../0_stateless/02000_table_function_cluster_macros.sql | 2 ++ 4 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 tests/queries/0_stateless/02000_table_function_cluster_macros.reference create mode 100644 tests/queries/0_stateless/02000_table_function_cluster_macros.sql diff --git a/src/TableFunctions/TableFunctionRemote.cpp b/src/TableFunctions/TableFunctionRemote.cpp index 34e9c1bff4f..08f61a49fa5 100644 --- a/src/TableFunctions/TableFunctionRemote.cpp +++ b/src/TableFunctions/TableFunctionRemote.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -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 { diff --git a/tests/config/config.d/macros.xml b/tests/config/config.d/macros.xml index 4902b12bc81..b17eb40099d 100644 --- a/tests/config/config.d/macros.xml +++ b/tests/config/config.d/macros.xml @@ -1,6 +1,7 @@ Hello, world! + test_shard_localhost s1 r1 /clickhouse/tables/{database}/{shard}/ diff --git a/tests/queries/0_stateless/02000_table_function_cluster_macros.reference b/tests/queries/0_stateless/02000_table_function_cluster_macros.reference new file mode 100644 index 00000000000..6ed281c757a --- /dev/null +++ b/tests/queries/0_stateless/02000_table_function_cluster_macros.reference @@ -0,0 +1,2 @@ +1 +1 diff --git a/tests/queries/0_stateless/02000_table_function_cluster_macros.sql b/tests/queries/0_stateless/02000_table_function_cluster_macros.sql new file mode 100644 index 00000000000..f1bc1358b55 --- /dev/null +++ b/tests/queries/0_stateless/02000_table_function_cluster_macros.sql @@ -0,0 +1,2 @@ +SELECT _shard_num FROM cluster("{default_cluster_macro}", system.one); +SELECT _shard_num FROM clusterAllReplicas("{default_cluster_macro}", system.one);