| 1 | #include <Parsers/ParserSystemQuery.h> |
| 2 | #include <Parsers/ASTSystemQuery.h> |
| 3 | #include <Parsers/CommonParsers.h> |
| 4 | #include <Parsers/ExpressionElementParsers.h> |
| 5 | #include <Parsers/ASTLiteral.h> |
| 6 | #include <Parsers/parseDatabaseAndTableName.h> |
| 7 | |
| 8 | |
| 9 | namespace ErrorCodes |
| 10 | { |
| 11 | extern const int NOT_IMPLEMENTED; |
| 12 | } |
| 13 | |
| 14 | |
| 15 | namespace DB |
| 16 | { |
| 17 | |
| 18 | |
| 19 | bool ParserSystemQuery::parseImpl(IParser::Pos & pos, ASTPtr & node, Expected & expected) |
| 20 | { |
| 21 | if (!ParserKeyword{"SYSTEM" }.ignore(pos, expected)) |
| 22 | return false; |
| 23 | |
| 24 | using Type = ASTSystemQuery::Type; |
| 25 | |
| 26 | auto res = std::make_shared<ASTSystemQuery>(); |
| 27 | |
| 28 | bool found = false; |
| 29 | for (int i = static_cast<int>(Type::UNKNOWN) + 1; i < static_cast<int>(Type::END); ++i) |
| 30 | { |
| 31 | Type t = static_cast<Type>(i); |
| 32 | if (ParserKeyword{ASTSystemQuery::typeToString(t)}.ignore(pos, expected)) |
| 33 | { |
| 34 | res->type = t; |
| 35 | found = true; |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | if (!found) |
| 40 | return false; |
| 41 | |
| 42 | switch (res->type) |
| 43 | { |
| 44 | case Type::RELOAD_DICTIONARY: |
| 45 | { |
| 46 | String cluster_str; |
| 47 | if (ParserKeyword{"ON" }.ignore(pos, expected)) |
| 48 | { |
| 49 | if (!ASTQueryWithOnCluster::parse(pos, cluster_str, expected)) |
| 50 | return false; |
| 51 | } |
| 52 | res->cluster = cluster_str; |
| 53 | ASTPtr ast; |
| 54 | if (ParserStringLiteral{}.parse(pos, ast, expected)) |
| 55 | res->target_dictionary = ast->as<ASTLiteral &>().value.safeGet<String>(); |
| 56 | else if (!parseDatabaseAndTableName(pos, expected, res->database, res->target_dictionary)) |
| 57 | return false; |
| 58 | break; |
| 59 | } |
| 60 | |
| 61 | case Type::RESTART_REPLICA: |
| 62 | case Type::SYNC_REPLICA: |
| 63 | case Type::FLUSH_DISTRIBUTED: |
| 64 | if (!parseDatabaseAndTableName(pos, expected, res->database, res->table)) |
| 65 | return false; |
| 66 | break; |
| 67 | |
| 68 | case Type::STOP_MERGES: |
| 69 | case Type::START_MERGES: |
| 70 | case Type::STOP_TTL_MERGES: |
| 71 | case Type::START_TTL_MERGES: |
| 72 | case Type::STOP_MOVES: |
| 73 | case Type::START_MOVES: |
| 74 | case Type::STOP_FETCHES: |
| 75 | case Type::START_FETCHES: |
| 76 | case Type::STOP_REPLICATED_SENDS: |
| 77 | case Type::START_REPLICATED_SENDS: |
| 78 | case Type::STOP_REPLICATION_QUEUES: |
| 79 | case Type::START_REPLICATION_QUEUES: |
| 80 | case Type::STOP_DISTRIBUTED_SENDS: |
| 81 | case Type::START_DISTRIBUTED_SENDS: |
| 82 | parseDatabaseAndTableName(pos, expected, res->database, res->table); |
| 83 | break; |
| 84 | |
| 85 | default: |
| 86 | /// There are no [db.table] after COMMAND NAME |
| 87 | break; |
| 88 | } |
| 89 | |
| 90 | node = std::move(res); |
| 91 | return true; |
| 92 | } |
| 93 | |
| 94 | } |
| 95 | |