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

Method parseImpl

src/Parsers/ParserUpdateQuery.cpp:17–119  ·  view source on GitHub ↗

To get more info of the grammar, see ASTUpdateQuery.h .

Source from the content-addressed store, hash-verified

15
16/// To get more info of the grammar, see ASTUpdateQuery.h .
17bool ParserUpdateQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
18{
19 auto query = std::make_shared<ASTUpdateQuery>();
20 node = query;
21
22 ParserKeyword s_update("UPDATE");
23 ParserKeyword s_set("SET");
24 ParserKeyword s_where("WHERE");
25 ParserKeyword s_order_by("ORDER BY");
26 ParserKeyword s_limit("LIMIT");
27 ParserKeyword s_settings("SETTINGS");
28
29 ParserList parser_assignment_list(std::make_unique<ParserAssignmentWithAlias>(dt), std::make_unique<ParserToken>(TokenType::Comma), false);
30 ParserExpression exp_list(dt);
31 ParserOrderByExpressionList order_list(dt);
32 ParserExpressionWithOptionalAlias exp_elem(false, dt);
33
34 if (!s_update.ignore(pos, expected))
35 return false;
36
37 auto pos_before = pos;
38 /// extract the target table
39 if (!parseDatabaseAndTableName(pos, expected, query->database, query->table))
40 return false;
41
42 if (s_set.ignore(pos, expected))
43 {
44 /// If the target table is followed by the word 'SET', it means it's a UPDATE SINGLE TABLE query, and all tables are extracted.
45 query->single_table = true;
46 }
47 else
48 {
49 /// For UPDATE JOIN, we already extract the target table and store the info to query->database and query->table.
50 /// To parse the whole `tables` correctly, we need to retrace tokens from the beginning of target table.
51 query->single_table = false;
52 pos = pos_before;
53
54 /// extract all tables
55 if (!ParserTablesInSelectQuery(dt).parse(pos, query->tables, expected))
56 return false;
57
58 if (!s_set.ignore(pos, expected))
59 return false;
60 }
61
62 if (!parser_assignment_list.parse(pos, query->assignment_list, expected))
63 return false;
64
65 if (s_where.ignore(pos, expected))
66 {
67 if (!exp_list.parse(pos, query->where_condition, expected))
68 return false;
69 }
70
71 if (s_order_by.ignore(pos, expected))
72 {
73 if (!order_list.parse(pos, query->order_by_expr, expected))
74 return false;

Callers

nothing calls this directly

Calls 5

ignoreMethod · 0.45
parseMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected