mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-13 18:02:24 +00:00
70d1adfe4b
* save format string for NetException * format exceptions * format exceptions 2 * format exceptions 3 * format exceptions 4 * format exceptions 5 * format exceptions 6 * fix * format exceptions 7 * format exceptions 8 * Update MergeTreeIndexGin.cpp * Update AggregateFunctionMap.cpp * Update AggregateFunctionMap.cpp * fix
71 lines
1.6 KiB
C++
71 lines
1.6 KiB
C++
#include <Parsers/IAST.h>
|
|
#include <Parsers/ASTIdentifier.h>
|
|
#include <Parsers/ASTLiteral.h>
|
|
#include <Parsers/ASTFunction.h>
|
|
#include <Storages/checkAndGetLiteralArgument.h>
|
|
#include <Common/typeid_cast.h>
|
|
|
|
#include <Interpreters/getClusterName.h>
|
|
|
|
|
|
namespace DB
|
|
{
|
|
|
|
namespace ErrorCodes
|
|
{
|
|
extern const int BAD_ARGUMENTS;
|
|
}
|
|
|
|
|
|
std::string getClusterName(const IAST & node)
|
|
{
|
|
auto name = tryGetClusterName(node);
|
|
if (!name)
|
|
throw Exception(ErrorCodes::BAD_ARGUMENTS, "Illegal expression instead of cluster name.");
|
|
return std::move(name).value();
|
|
}
|
|
|
|
|
|
std::optional<std::string> tryGetClusterName(const IAST & node)
|
|
{
|
|
if (const auto * ast_id = node.as<ASTIdentifier>())
|
|
return ast_id->name();
|
|
|
|
if (const auto * ast_lit = node.as<ASTLiteral>())
|
|
{
|
|
if (ast_lit->value.getType() != Field::Types::String)
|
|
return {};
|
|
return ast_lit->value.safeGet<String>();
|
|
}
|
|
|
|
/// A hack to support hyphens in cluster names.
|
|
if (const auto * ast_func = node.as<ASTFunction>())
|
|
{
|
|
if (ast_func->name != "minus" || !ast_func->arguments || ast_func->arguments->children.size() < 2)
|
|
return {};
|
|
|
|
String name;
|
|
for (const auto & arg : ast_func->arguments->children)
|
|
{
|
|
if (name.empty())
|
|
name += getClusterName(*arg);
|
|
else
|
|
name += "-" + getClusterName(*arg);
|
|
}
|
|
|
|
return name;
|
|
}
|
|
|
|
return {};
|
|
}
|
|
|
|
|
|
std::string getClusterNameAndMakeLiteral(ASTPtr & node)
|
|
{
|
|
String cluster_name = getClusterName(*node);
|
|
node = std::make_shared<ASTLiteral>(cluster_name);
|
|
return cluster_name;
|
|
}
|
|
|
|
}
|