MCPcopy Create free account
hub / github.com/ByConity/ByConity / parseMySQLDDLQuery

Function parseMySQLDDLQuery

src/Databases/MySQL/MaterializedMySQLCommon.cpp:38–113  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

36}
37
38MySQLDDLQueryParams parseMySQLDDLQuery(const String & ddl)
39{
40 MySQLDDLQueryParams params;
41 params.query = ddl;
42 if (ddl.empty()) return params;
43
44 bool parse_failed = false;
45 Tokens tokens(ddl.data(), ddl.data() + ddl.size());
46 IParser::Pos pos(tokens, 0);
47 Expected expected;
48 ASTPtr res;
49 ASTPtr table;
50 if (ParserKeyword("CREATE TEMPORARY TABLE").ignore(pos, expected) || ParserKeyword("CREATE TABLE").ignore(pos, expected))
51 {
52 ParserKeyword("IF NOT EXISTS").ignore(pos, expected);
53 if (!ParserCompoundIdentifier(true).parse(pos, table, expected))
54 parse_failed = true;
55 else
56 params.query_type = MySQLDDLQueryParams::CREATE_TABLE;
57 }
58 else if (ParserKeyword("ALTER TABLE").ignore(pos, expected))
59 {
60 if (!ParserCompoundIdentifier(true).parse(pos, table, expected))
61 parse_failed = true;
62 else
63 params.query_type = MySQLDDLQueryParams::ALTER_TABLE;
64 }
65 else if (ParserKeyword("DROP TABLE").ignore(pos, expected) || ParserKeyword("DROP TEMPORARY TABLE").ignore(pos, expected))
66 {
67 ParserKeyword("IF EXISTS").ignore(pos, expected);
68 if (!ParserCompoundIdentifier(true).parse(pos, table, expected))
69 parse_failed = true;
70 else
71 params.query_type = MySQLDDLQueryParams::DROP_TABLE;
72 }
73 else if (ParserKeyword("TRUNCATE").ignore(pos, expected))
74 {
75 ParserKeyword("TABLE").ignore(pos, expected);
76 if (!ParserCompoundIdentifier(true).parse(pos, table, expected))
77 parse_failed = true;
78 else
79 params.query_type = MySQLDDLQueryParams::TRUNCATE_TABLE;
80 }
81 else if (ParserKeyword("RENAME TABLE").ignore(pos, expected))
82 {
83 if (!ParserCompoundIdentifier(true).parse(pos, table, expected))
84 parse_failed = true;
85 else
86 {
87 ParserKeyword("TO").ignore(pos, expected);
88 ASTPtr to_table;
89 if (!ParserCompoundIdentifier(true).parse(pos, to_table, expected))
90 parse_failed = true;
91 else
92 {
93 params.query_type = MySQLDDLQueryParams::RENAME_TABLE;
94
95 auto storage_id = to_table->as<ASTTableIdentifier>()->getTableId();

Callers 2

executeDDLQueryMethod · 0.85
executeDDLAtomicMethod · 0.85

Calls 8

ParserKeywordClass · 0.85
getTableIdMethod · 0.80
emptyMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45
ignoreMethod · 0.45
parseMethod · 0.45

Tested by

no test coverage detected