2017-04-01 09:19:00 +00:00
|
|
|
#include <Parsers/IAST.h>
|
|
|
|
#include <Parsers/ASTIdentifier.h>
|
|
|
|
#include <Parsers/ASTLiteral.h>
|
|
|
|
#include <Parsers/ASTFunction.h>
|
|
|
|
#include <Common/typeid_cast.h>
|
2016-05-13 03:22:16 +00:00
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Interpreters/getClusterName.h>
|
2016-05-13 03:22:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2017-01-06 17:41:19 +00:00
|
|
|
namespace ErrorCodes
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
extern const int BAD_ARGUMENTS;
|
2017-01-06 17:41:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-13 03:22:16 +00:00
|
|
|
std::string getClusterName(const IAST & node)
|
|
|
|
{
|
2019-03-08 09:45:34 +00:00
|
|
|
if (const auto * ast_id = node.As<ASTIdentifier>())
|
2017-04-01 07:20:54 +00:00
|
|
|
return ast_id->name;
|
2016-05-13 03:22:16 +00:00
|
|
|
|
2019-03-08 09:45:34 +00:00
|
|
|
if (const auto * ast_lit = node.As<ASTLiteral>())
|
2017-04-01 07:20:54 +00:00
|
|
|
return ast_lit->value.safeGet<String>();
|
2016-05-13 03:22:16 +00:00
|
|
|
|
2019-01-18 16:30:35 +00:00
|
|
|
/// A hack to support hyphens in cluster names.
|
2019-03-08 09:45:34 +00:00
|
|
|
if (const auto * ast_func = node.As<ASTFunction>())
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
2019-01-18 16:30:35 +00:00
|
|
|
if (ast_func->name != "minus" || !ast_func->arguments || ast_func->arguments->children.size() < 2)
|
2017-04-01 07:20:54 +00:00
|
|
|
throw Exception("Illegal expression instead of cluster name.", ErrorCodes::BAD_ARGUMENTS);
|
2016-05-13 03:22:16 +00:00
|
|
|
|
2019-01-18 16:30:35 +00:00
|
|
|
String name;
|
|
|
|
for (const auto & arg : ast_func->arguments->children)
|
|
|
|
{
|
|
|
|
if (name.empty())
|
|
|
|
name += getClusterName(*arg);
|
|
|
|
else
|
|
|
|
name += "-" + getClusterName(*arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
return name;
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
2016-05-13 03:22:16 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
throw Exception("Illegal expression instead of cluster name.", ErrorCodes::BAD_ARGUMENTS);
|
2016-05-13 03:22:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|