blob: 59f0ada4e32aa9d491e8dd7479a39271eae317df (
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
|
#include <Parsers/MySQL/ASTAlterQuery.h>
#include <Interpreters/StorageID.h>
#include <Common/quoteString.h>
#include <Parsers/ASTIdentifier.h>
#include <Parsers/CommonParsers.h>
#include <Parsers/ExpressionElementParsers.h>
#include <Parsers/ExpressionListParsers.h>
#include <Parsers/MySQL/ASTAlterCommand.h>
namespace DB
{
namespace MySQLParser
{
ASTPtr ASTAlterQuery::clone() const
{
auto res = std::make_shared<ASTAlterQuery>(*this);
res->children.clear();
if (command_list)
{
res->command_list = command_list->clone();
res->children.emplace_back(res->command_list);
}
return res;
}
bool ParserAlterQuery::parseImpl(IParser::Pos & pos, ASTPtr & node, Expected & expected)
{
ASTPtr table;
ASTPtr command_list;
if (!ParserKeyword("ALTER TABLE").ignore(pos, expected))
return false;
if (!ParserCompoundIdentifier(true).parse(pos, table, expected))
return false;
if (!ParserList(std::make_unique<ParserAlterCommand>(), std::make_unique<ParserToken>(TokenType::Comma)).parse(pos, command_list, expected))
return false;
auto alter_query = std::make_shared<ASTAlterQuery>();
node = alter_query;
alter_query->command_list = command_list;
auto table_id = table->as<ASTTableIdentifier>()->getTableId();
alter_query->table = table_id.table_name;
alter_query->database = table_id.database_name;
if (alter_query->command_list)
alter_query->children.emplace_back(alter_query->command_list);
return true;
}
}
}
|