1#include <Parsers/ASTIdentifier.h>
2#include <Parsers/ASTLiteral.h>
3#include <Parsers/ASTSetQuery.h>
4
5#include <Parsers/CommonParsers.h>
6#include <Parsers/ParserSetQuery.h>
7
8#include <Common/typeid_cast.h>
9
10
11namespace DB
12{
13
14
15/// Parse `name = value`.
16static bool parseNameValuePair(SettingChange & change, IParser::Pos & pos, Expected & expected)
17{
18 ParserIdentifier name_p;
19 ParserLiteral value_p;
20 ParserToken s_eq(TokenType::Equals);
21
22 ASTPtr name;
23 ASTPtr value;
24
25 if (!name_p.parse(pos, name, expected))
26 return false;
27
28 if (!s_eq.ignore(pos, expected))
29 return false;
30
31 if (!value_p.parse(pos, value, expected))
32 return false;
33
34 tryGetIdentifierNameInto(name, change.name);
35 change.value = value->as<ASTLiteral &>().value;
36
37 return true;
38}
39
40
41bool ParserSetQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
42{
43 ParserToken s_comma(TokenType::Comma);
44
45 if (!parse_only_internals)
46 {
47 ParserKeyword s_set("SET");
48
49 if (!s_set.ignore(pos, expected))
50 return false;
51 }
52
53 SettingsChanges changes;
54
55 while (true)
56 {
57 if (!changes.empty() && !s_comma.ignore(pos))
58 break;
59
60 changes.push_back(SettingChange{});
61
62 if (!parseNameValuePair(changes.back(), pos, expected))
63 return false;
64 }
65
66 auto query = std::make_shared<ASTSetQuery>();
67 node = query;
68
69 query->is_standalone = !parse_only_internals;
70 query->changes = std::move(changes);
71
72 return true;
73}
74
75
76}
77