aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/Parsers/ParserUndropQuery.cpp
blob: 3784ab0f3539983980686096198ef58caf61cd96 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include <Parsers/ASTUndropQuery.h>

#include <Parsers/CommonParsers.h>
#include <Parsers/ParserUndropQuery.h>
#include "Parsers/ASTLiteral.h"


namespace DB
{

namespace
{

bool parseUndropQuery(IParser::Pos & pos, ASTPtr & node, Expected & expected)
{
    ParserKeyword s_table("TABLE");
    ParserToken s_dot(TokenType::Dot);
    ParserIdentifier name_p(true);

    ASTPtr database;
    ASTPtr table;
    String cluster_str;
    /// We can specify the table's uuid for exact undrop.
    /// because the same name of a table can be created and deleted multiple times,
    /// and can generate multiple different uuids.
    UUID uuid = UUIDHelpers::Nil;

    if (!s_table.ignore(pos, expected))
        return false;
    if (!name_p.parse(pos, table, expected))
        return false;
    if (s_dot.ignore(pos, expected))
    {
        database = table;
        if (!name_p.parse(pos, table, expected))
            return false;
    }
    if (ParserKeyword("UUID").ignore(pos, expected))
    {
        ParserStringLiteral uuid_p;
        ASTPtr ast_uuid;
        if (!uuid_p.parse(pos, ast_uuid, expected))
            return false;
        uuid = parseFromString<UUID>(ast_uuid->as<ASTLiteral>()->value.get<String>());
    }
    if (ParserKeyword{"ON"}.ignore(pos, expected))
    {
        if (!ASTQueryWithOnCluster::parse(pos, cluster_str, expected))
            return false;
    }
    auto query = std::make_shared<ASTUndropQuery>();
    node = query;

    query->database = database;
    query->table = table;
    query->uuid = uuid;

    if (database)
        query->children.push_back(database);

    assert (table);
    query->children.push_back(table);

    query->cluster = cluster_str;

    return true;
}

}

bool ParserUndropQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
{
    ParserKeyword s_undrop("UNDROP");

    if (s_undrop.ignore(pos, expected))
        return parseUndropQuery(pos, node, expected);
    else
        return false;
}

}