2016-05-13 03:22:16 +00:00
|
|
|
#include <DB/Parsers/IAST.h>
|
|
|
|
#include <DB/Parsers/ASTIdentifier.h>
|
|
|
|
#include <DB/Parsers/ASTLiteral.h>
|
|
|
|
#include <DB/Parsers/ASTFunction.h>
|
2016-11-20 12:43:20 +00:00
|
|
|
#include <DB/Common/typeid_cast.h>
|
2016-05-13 03:22:16 +00:00
|
|
|
|
|
|
|
#include <DB/Interpreters/getClusterName.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2017-01-06 17:41:19 +00:00
|
|
|
namespace ErrorCodes
|
|
|
|
{
|
|
|
|
extern const int BAD_ARGUMENTS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-13 03:22:16 +00:00
|
|
|
std::string getClusterName(const IAST & node)
|
|
|
|
{
|
|
|
|
if (const ASTIdentifier * ast_id = typeid_cast<const ASTIdentifier *>(&node))
|
|
|
|
return ast_id->name;
|
|
|
|
|
|
|
|
if (const ASTLiteral * ast_lit = typeid_cast<const ASTLiteral *>(&node))
|
|
|
|
return ast_lit->value.safeGet<String>();
|
|
|
|
|
|
|
|
if (const ASTFunction * ast_func = typeid_cast<const ASTFunction *>(&node))
|
|
|
|
{
|
|
|
|
if (!ast_func->range.first || !ast_func->range.second)
|
|
|
|
throw Exception("Illegal expression instead of cluster name.", ErrorCodes::BAD_ARGUMENTS);
|
|
|
|
|
|
|
|
return String(ast_func->range.first, ast_func->range.second);
|
|
|
|
}
|
|
|
|
|
|
|
|
throw Exception("Illegal expression instead of cluster name.", ErrorCodes::BAD_ARGUMENTS);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|