aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/Parsers/MySQL/ASTDeclareSubPartition.cpp
blob: d77fba271c47f479e75d3e1e65e13f14936d658e (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
#include <Parsers/MySQL/ASTDeclareSubPartition.h>

#include <Parsers/ASTIdentifier.h>
#include <Parsers/CommonParsers.h>
#include <Parsers/MySQL/ASTDeclareOption.h>
#include <Parsers/ExpressionElementParsers.h>

namespace DB
{

namespace MySQLParser
{

bool ParserDeclareSubPartition::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
{
    if (!ParserKeyword{"SUBPARTITION"}.ignore(pos, expected))
        return false;

    ASTPtr options;
    ASTPtr logical_name;
    ParserIdentifier p_identifier;

    if (!p_identifier.parse(pos, logical_name, expected))
        return false;

    ParserDeclareOptions options_p{
        {
            OptionDescribe("ENGINE", "engine", std::make_shared<ParserIdentifier>()),
            OptionDescribe("STORAGE ENGINE", "engine", std::make_shared<ParserIdentifier>()),
            OptionDescribe("COMMENT", "comment", std::make_shared<ParserStringLiteral>()),
            OptionDescribe("DATA DIRECTORY", "data_directory", std::make_shared<ParserStringLiteral>()),
            OptionDescribe("INDEX DIRECTORY", "index_directory", std::make_shared<ParserStringLiteral>()),
            OptionDescribe("MAX_ROWS", "max_rows", std::make_shared<ParserLiteral>()),
            OptionDescribe("MIN_ROWS", "min_rows", std::make_shared<ParserLiteral>()),
            OptionDescribe("TABLESPACE", "tablespace", std::make_shared<ParserIdentifier>()),
        }
    };

    /// Optional options
    options_p.parse(pos, options, expected);

    auto subpartition_declare = std::make_shared<ASTDeclareSubPartition>();
    subpartition_declare->options = options;
    subpartition_declare->logical_name = logical_name->as<ASTIdentifier>()->name();

    if (options)
    {
        subpartition_declare->options = options;
        subpartition_declare->children.emplace_back(subpartition_declare->options);
    }

    node = subpartition_declare;
    return true;
}

ASTPtr ASTDeclareSubPartition::clone() const
{
    auto res = std::make_shared<ASTDeclareSubPartition>(*this);
    res->children.clear();

    if (options)
    {
        res->options = options->clone();
        res->children.emplace_back(res->options);
    }

    return res;
}
}

}