2017-08-04 15:54:00 +00:00
|
|
|
#include <Parsers/ParserSystemQuery.h>
|
|
|
|
#include <Parsers/ASTSystemQuery.h>
|
|
|
|
#include <Parsers/CommonParsers.h>
|
2019-12-15 13:48:11 +00:00
|
|
|
#include <Parsers/ExpressionElementParsers.h>
|
|
|
|
#include <Parsers/ASTLiteral.h>
|
2018-05-21 13:49:54 +00:00
|
|
|
#include <Parsers/parseDatabaseAndTableName.h>
|
2017-08-04 15:54:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace ErrorCodes
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
bool ParserSystemQuery::parseImpl(IParser::Pos & pos, ASTPtr & node, Expected & expected)
|
|
|
|
{
|
2019-12-07 23:05:57 +00:00
|
|
|
if (!ParserKeyword{"SYSTEM"}.ignore(pos, expected))
|
2017-08-04 15:54:00 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
using Type = ASTSystemQuery::Type;
|
|
|
|
|
|
|
|
auto res = std::make_shared<ASTSystemQuery>();
|
|
|
|
|
|
|
|
bool found = false;
|
2017-08-31 12:55:19 +00:00
|
|
|
for (int i = static_cast<int>(Type::UNKNOWN) + 1; i < static_cast<int>(Type::END); ++i)
|
2017-08-04 15:54:00 +00:00
|
|
|
{
|
|
|
|
Type t = static_cast<Type>(i);
|
2019-12-07 23:05:57 +00:00
|
|
|
if (ParserKeyword{ASTSystemQuery::typeToString(t)}.ignore(pos, expected))
|
2017-08-04 15:54:00 +00:00
|
|
|
{
|
|
|
|
res->type = t;
|
|
|
|
found = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found)
|
|
|
|
return false;
|
|
|
|
|
2018-05-21 13:49:54 +00:00
|
|
|
switch (res->type)
|
2017-08-04 15:54:00 +00:00
|
|
|
{
|
2018-05-21 13:49:54 +00:00
|
|
|
case Type::RELOAD_DICTIONARY:
|
2019-12-15 13:48:11 +00:00
|
|
|
{
|
2019-12-23 03:48:34 +00:00
|
|
|
String cluster_str;
|
2019-12-19 03:46:20 +00:00
|
|
|
if (ParserKeyword{"ON"}.ignore(pos, expected))
|
|
|
|
{
|
2019-12-19 07:54:43 +00:00
|
|
|
if (!ASTQueryWithOnCluster::parse(pos, cluster_str, expected))
|
2019-12-19 03:46:20 +00:00
|
|
|
return false;
|
|
|
|
}
|
2019-12-19 07:54:43 +00:00
|
|
|
res->cluster = cluster_str;
|
2019-12-15 13:48:11 +00:00
|
|
|
ASTPtr ast;
|
|
|
|
if (ParserStringLiteral{}.parse(pos, ast, expected))
|
|
|
|
res->target_dictionary = ast->as<ASTLiteral &>().value.safeGet<String>();
|
2019-12-23 03:48:34 +00:00
|
|
|
else if (!parseDatabaseAndTableName(pos, expected, res->database, res->target_dictionary))
|
2018-05-21 13:49:54 +00:00
|
|
|
return false;
|
|
|
|
break;
|
2019-12-15 13:48:11 +00:00
|
|
|
}
|
2018-05-21 13:49:54 +00:00
|
|
|
|
|
|
|
case Type::RESTART_REPLICA:
|
|
|
|
case Type::SYNC_REPLICA:
|
2020-06-03 18:51:49 +00:00
|
|
|
if (!parseDatabaseAndTableName(pos, expected, res->database, res->table))
|
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Type::STOP_DISTRIBUTED_SENDS:
|
|
|
|
case Type::START_DISTRIBUTED_SENDS:
|
2019-05-10 04:19:02 +00:00
|
|
|
case Type::FLUSH_DISTRIBUTED:
|
2020-06-03 18:51:49 +00:00
|
|
|
{
|
|
|
|
String cluster_str;
|
|
|
|
if (ParserKeyword{"ON"}.ignore(pos, expected))
|
|
|
|
{
|
|
|
|
if (!ASTQueryWithOnCluster::parse(pos, cluster_str, expected))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
res->cluster = cluster_str;
|
2019-12-19 09:27:12 +00:00
|
|
|
if (!parseDatabaseAndTableName(pos, expected, res->database, res->table))
|
2020-06-04 17:22:29 +00:00
|
|
|
{
|
|
|
|
/// FLUSH DISTRIBUTED requires table
|
|
|
|
/// START/STOP DISTRIBUTED SENDS does not requires table
|
|
|
|
if (res->type == Type::FLUSH_DISTRIBUTED)
|
|
|
|
return false;
|
|
|
|
}
|
2018-05-21 13:49:54 +00:00
|
|
|
break;
|
2020-06-03 18:51:49 +00:00
|
|
|
}
|
2018-05-21 13:49:54 +00:00
|
|
|
|
|
|
|
case Type::STOP_MERGES:
|
|
|
|
case Type::START_MERGES:
|
2019-08-01 15:36:12 +00:00
|
|
|
case Type::STOP_TTL_MERGES:
|
|
|
|
case Type::START_TTL_MERGES:
|
2019-09-03 14:50:49 +00:00
|
|
|
case Type::STOP_MOVES:
|
|
|
|
case Type::START_MOVES:
|
2018-05-21 13:49:54 +00:00
|
|
|
case Type::STOP_FETCHES:
|
|
|
|
case Type::START_FETCHES:
|
|
|
|
case Type::STOP_REPLICATED_SENDS:
|
2019-02-02 11:28:43 +00:00
|
|
|
case Type::START_REPLICATED_SENDS:
|
2018-05-21 13:49:54 +00:00
|
|
|
case Type::STOP_REPLICATION_QUEUES:
|
|
|
|
case Type::START_REPLICATION_QUEUES:
|
2019-12-19 09:27:12 +00:00
|
|
|
parseDatabaseAndTableName(pos, expected, res->database, res->table);
|
2018-05-21 13:49:54 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
/// There are no [db.table] after COMMAND NAME
|
|
|
|
break;
|
2017-08-04 15:54:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
node = std::move(res);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|