2017-08-04 15:54:00 +00:00
|
|
|
#include <Parsers/IAST.h>
|
|
|
|
#include <Parsers/ASTSystemQuery.h>
|
2019-10-08 18:42:22 +00:00
|
|
|
#include <Common/quoteString.h>
|
2017-08-04 15:54:00 +00:00
|
|
|
|
|
|
|
|
2017-08-06 20:26:23 +00:00
|
|
|
namespace DB
|
2017-08-04 15:54:00 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
|
2017-08-06 20:26:23 +00:00
|
|
|
namespace ErrorCodes
|
2017-08-04 15:54:00 +00:00
|
|
|
{
|
2017-08-06 20:26:23 +00:00
|
|
|
extern const int BAD_TYPE_OF_FIELD;
|
|
|
|
}
|
2017-08-04 15:54:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
const char * ASTSystemQuery::typeToString(Type type)
|
|
|
|
{
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case Type::SHUTDOWN:
|
|
|
|
return "SHUTDOWN";
|
|
|
|
case Type::KILL:
|
|
|
|
return "KILL";
|
|
|
|
case Type::DROP_DNS_CACHE:
|
|
|
|
return "DROP DNS CACHE";
|
|
|
|
case Type::DROP_MARK_CACHE:
|
|
|
|
return "DROP MARK CACHE";
|
|
|
|
case Type::DROP_UNCOMPRESSED_CACHE:
|
|
|
|
return "DROP UNCOMPRESSED CACHE";
|
2018-08-30 16:31:20 +00:00
|
|
|
#if USE_EMBEDDED_COMPILER
|
2018-09-05 11:37:41 +00:00
|
|
|
case Type::DROP_COMPILED_EXPRESSION_CACHE:
|
|
|
|
return "DROP COMPILED EXPRESSION CACHE";
|
2018-08-30 16:31:20 +00:00
|
|
|
#endif
|
2017-08-04 15:54:00 +00:00
|
|
|
case Type::STOP_LISTEN_QUERIES:
|
|
|
|
return "STOP LISTEN QUERIES";
|
|
|
|
case Type::START_LISTEN_QUERIES:
|
|
|
|
return "START LISTEN QUERIES";
|
|
|
|
case Type::RESTART_REPLICAS:
|
|
|
|
return "RESTART REPLICAS";
|
2018-05-21 13:49:54 +00:00
|
|
|
case Type::RESTART_REPLICA:
|
|
|
|
return "RESTART REPLICA";
|
2020-05-17 12:44:22 +00:00
|
|
|
case Type::DROP_REPLICA:
|
|
|
|
return "DROP REPLICA";
|
2017-08-04 15:54:00 +00:00
|
|
|
case Type::SYNC_REPLICA:
|
|
|
|
return "SYNC REPLICA";
|
2019-05-10 04:19:02 +00:00
|
|
|
case Type::FLUSH_DISTRIBUTED:
|
|
|
|
return "FLUSH DISTRIBUTED";
|
2017-08-04 15:54:00 +00:00
|
|
|
case Type::RELOAD_DICTIONARY:
|
|
|
|
return "RELOAD DICTIONARY";
|
|
|
|
case Type::RELOAD_DICTIONARIES:
|
|
|
|
return "RELOAD DICTIONARIES";
|
2018-03-26 14:12:07 +00:00
|
|
|
case Type::RELOAD_EMBEDDED_DICTIONARIES:
|
|
|
|
return "RELOAD EMBEDDED DICTIONARIES";
|
2018-03-13 10:41:47 +00:00
|
|
|
case Type::RELOAD_CONFIG:
|
|
|
|
return "RELOAD CONFIG";
|
2017-08-04 15:54:00 +00:00
|
|
|
case Type::STOP_MERGES:
|
|
|
|
return "STOP MERGES";
|
|
|
|
case Type::START_MERGES:
|
|
|
|
return "START MERGES";
|
2019-08-01 15:36:12 +00:00
|
|
|
case Type::STOP_TTL_MERGES:
|
|
|
|
return "STOP TTL MERGES";
|
|
|
|
case Type::START_TTL_MERGES:
|
|
|
|
return "START TTL MERGES";
|
2019-09-03 14:50:49 +00:00
|
|
|
case Type::STOP_MOVES:
|
|
|
|
return "STOP MOVES";
|
|
|
|
case Type::START_MOVES:
|
|
|
|
return "START MOVES";
|
2018-05-21 13:49:54 +00:00
|
|
|
case Type::STOP_FETCHES:
|
|
|
|
return "STOP FETCHES";
|
|
|
|
case Type::START_FETCHES:
|
|
|
|
return "START FETCHES";
|
|
|
|
case Type::STOP_REPLICATED_SENDS:
|
|
|
|
return "STOP REPLICATED SENDS";
|
2019-02-02 11:28:43 +00:00
|
|
|
case Type::START_REPLICATED_SENDS:
|
2018-05-21 13:49:54 +00:00
|
|
|
return "START REPLICATED SENDS";
|
2017-08-04 15:54:00 +00:00
|
|
|
case Type::STOP_REPLICATION_QUEUES:
|
|
|
|
return "STOP REPLICATION QUEUES";
|
|
|
|
case Type::START_REPLICATION_QUEUES:
|
|
|
|
return "START REPLICATION QUEUES";
|
2019-04-22 15:11:16 +00:00
|
|
|
case Type::STOP_DISTRIBUTED_SENDS:
|
|
|
|
return "STOP DISTRIBUTED SENDS";
|
|
|
|
case Type::START_DISTRIBUTED_SENDS:
|
|
|
|
return "START DISTRIBUTED SENDS";
|
2018-10-09 10:05:27 +00:00
|
|
|
case Type::FLUSH_LOGS:
|
|
|
|
return "FLUSH LOGS";
|
2017-08-04 15:54:00 +00:00
|
|
|
default:
|
|
|
|
throw Exception("Unknown SYSTEM query command", ErrorCodes::BAD_TYPE_OF_FIELD);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-01 18:36:55 +00:00
|
|
|
void ASTSystemQuery::formatImpl(const FormatSettings & settings, FormatState &, FormatStateStacked) const
|
2017-08-06 20:26:23 +00:00
|
|
|
{
|
|
|
|
settings.ostr << (settings.hilite ? hilite_keyword : "") << "SYSTEM " << (settings.hilite ? hilite_none : "");
|
|
|
|
settings.ostr << typeToString(type);
|
|
|
|
|
2019-12-15 13:48:11 +00:00
|
|
|
auto print_database_table = [&]
|
2018-05-21 13:49:54 +00:00
|
|
|
{
|
|
|
|
settings.ostr << " ";
|
2019-12-19 03:46:20 +00:00
|
|
|
if (!database.empty())
|
2018-05-21 13:49:54 +00:00
|
|
|
{
|
2019-12-19 03:46:20 +00:00
|
|
|
settings.ostr << (settings.hilite ? hilite_identifier : "") << backQuoteIfNeed(database)
|
2018-05-21 13:49:54 +00:00
|
|
|
<< (settings.hilite ? hilite_none : "") << ".";
|
|
|
|
}
|
2019-12-19 09:27:12 +00:00
|
|
|
settings.ostr << (settings.hilite ? hilite_identifier : "") << backQuoteIfNeed(table)
|
2018-05-21 13:49:54 +00:00
|
|
|
<< (settings.hilite ? hilite_none : "");
|
|
|
|
};
|
|
|
|
|
2019-12-15 13:48:11 +00:00
|
|
|
auto print_database_dictionary = [&]
|
|
|
|
{
|
|
|
|
settings.ostr << " ";
|
2019-12-23 03:46:02 +00:00
|
|
|
if (!database.empty())
|
2019-12-15 13:48:11 +00:00
|
|
|
{
|
2019-12-23 03:46:02 +00:00
|
|
|
settings.ostr << (settings.hilite ? hilite_identifier : "") << backQuoteIfNeed(database)
|
2019-12-15 13:48:11 +00:00
|
|
|
<< (settings.hilite ? hilite_none : "") << ".";
|
|
|
|
}
|
|
|
|
settings.ostr << (settings.hilite ? hilite_identifier : "") << backQuoteIfNeed(target_dictionary)
|
|
|
|
<< (settings.hilite ? hilite_none : "");
|
|
|
|
};
|
2019-12-23 03:48:34 +00:00
|
|
|
|
2020-05-17 12:44:22 +00:00
|
|
|
auto print_drop_replica = [&] {
|
2020-06-05 07:03:51 +00:00
|
|
|
settings.ostr << " " << quoteString(replica) << (settings.hilite ? hilite_none : "");
|
2020-05-17 12:44:22 +00:00
|
|
|
if (!table.empty())
|
2020-06-05 07:03:51 +00:00
|
|
|
{
|
|
|
|
settings.ostr << " FROM TABLE";
|
2020-05-17 12:44:22 +00:00
|
|
|
print_database_table();
|
2020-06-05 07:03:51 +00:00
|
|
|
}
|
|
|
|
else if (!replica_zk_path.empty())
|
2020-05-17 12:44:22 +00:00
|
|
|
{
|
2020-06-05 07:03:51 +00:00
|
|
|
settings.ostr << " FROM ZKPATH " << (settings.hilite ? hilite_identifier : "") << quoteString(replica_zk_path)
|
2020-05-17 12:44:22 +00:00
|
|
|
<< (settings.hilite ? hilite_none : "");
|
|
|
|
}
|
2020-06-05 07:03:51 +00:00
|
|
|
else if (!database.empty())
|
|
|
|
{
|
|
|
|
settings.ostr << " FROM DATABASE ";
|
|
|
|
settings.ostr << (settings.hilite ? hilite_identifier : "") << backQuoteIfNeed(database)
|
|
|
|
<< (settings.hilite ? hilite_none : "");
|
|
|
|
}
|
2020-05-17 12:44:22 +00:00
|
|
|
};
|
|
|
|
|
2019-12-19 03:46:20 +00:00
|
|
|
if (!cluster.empty())
|
2019-12-19 07:54:43 +00:00
|
|
|
formatOnCluster(settings);
|
2019-12-23 03:48:34 +00:00
|
|
|
|
2018-05-21 13:49:54 +00:00
|
|
|
if ( type == Type::STOP_MERGES
|
|
|
|
|| type == Type::START_MERGES
|
2019-08-01 15:36:12 +00:00
|
|
|
|| type == Type::STOP_TTL_MERGES
|
|
|
|
|| type == Type::START_TTL_MERGES
|
2019-09-03 14:50:49 +00:00
|
|
|
|| type == Type::STOP_MOVES
|
|
|
|
|| type == Type::START_MOVES
|
2018-05-21 13:49:54 +00:00
|
|
|
|| type == Type::STOP_FETCHES
|
|
|
|
|| type == Type::START_FETCHES
|
|
|
|
|| type == Type::STOP_REPLICATED_SENDS
|
2019-02-02 11:28:43 +00:00
|
|
|
|| type == Type::START_REPLICATED_SENDS
|
2018-05-21 13:49:54 +00:00
|
|
|
|| type == Type::STOP_REPLICATION_QUEUES
|
2019-04-22 15:11:16 +00:00
|
|
|
|| type == Type::START_REPLICATION_QUEUES
|
|
|
|
|| type == Type::STOP_DISTRIBUTED_SENDS
|
|
|
|
|| type == Type::START_DISTRIBUTED_SENDS)
|
2018-05-21 13:49:54 +00:00
|
|
|
{
|
2019-12-19 09:27:12 +00:00
|
|
|
if (!table.empty())
|
2018-05-21 13:49:54 +00:00
|
|
|
print_database_table();
|
|
|
|
}
|
2019-05-10 04:19:02 +00:00
|
|
|
else if (type == Type::RESTART_REPLICA || type == Type::SYNC_REPLICA || type == Type::FLUSH_DISTRIBUTED)
|
2018-05-21 13:49:54 +00:00
|
|
|
{
|
|
|
|
print_database_table();
|
|
|
|
}
|
|
|
|
else if (type == Type::RELOAD_DICTIONARY)
|
2019-12-15 13:48:11 +00:00
|
|
|
print_database_dictionary();
|
2020-05-17 12:44:22 +00:00
|
|
|
else if (type == Type::DROP_REPLICA)
|
|
|
|
print_drop_replica();
|
2017-08-06 20:26:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-08-30 21:25:44 +00:00
|
|
|
}
|