1/* Copyright (c) 2018 BlackBerry Limited
2
3Licensed under the Apache License, Version 2.0 (the "License");
4you may not use this file except in compliance with the License.
5You may obtain a copy of the License at
6http://www.apache.org/licenses/LICENSE-2.0
7Unless required by applicable law or agreed to in writing, software
8distributed under the License is distributed on an "AS IS" BASIS,
9WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10See the License for the specific language governing permissions and
11limitations under the License. */
12#include <Parsers/ASTLiteral.h>
13#include <Parsers/ASTIdentifier.h>
14#include <Parsers/ASTWatchQuery.h>
15#include <Parsers/CommonParsers.h>
16#include <Parsers/ParserWatchQuery.h>
17#include <Parsers/ExpressionElementParsers.h>
18
19
20namespace DB
21{
22
23bool ParserWatchQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
24{
25 ParserKeyword s_watch("WATCH");
26 ParserToken s_dot(TokenType::Dot);
27 ParserIdentifier name_p;
28 ParserKeyword s_events("EVENTS");
29 ParserKeyword s_limit("LIMIT");
30
31 ASTPtr database;
32 ASTPtr table;
33 auto query = std::make_shared<ASTWatchQuery>();
34
35 if (!s_watch.ignore(pos, expected))
36 {
37 return false;
38 }
39
40 if (!name_p.parse(pos, table, expected))
41 return false;
42
43 if (s_dot.ignore(pos, expected))
44 {
45 database = table;
46 if (!name_p.parse(pos, table, expected))
47 return false;
48 }
49
50 /// EVENTS
51 if (s_events.ignore(pos, expected))
52 {
53 query->is_watch_events = true;
54 }
55
56 /// LIMIT length
57 if (s_limit.ignore(pos, expected))
58 {
59 ParserNumber num;
60
61 if (!num.parse(pos, query->limit_length, expected))
62 return false;
63 }
64
65 if (database)
66 query->database = getIdentifierName(database);
67
68 if (table)
69 query->table = getIdentifierName(table);
70
71 node = query;
72
73 return true;
74}
75
76
77}
78