| 1 | /* Copyright (c) 2018 BlackBerry Limited |
| 2 | |
| 3 | Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | you may not use this file except in compliance with the License. |
| 5 | You may obtain a copy of the License at |
| 6 | http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | Unless required by applicable law or agreed to in writing, software |
| 8 | distributed under the License is distributed on an "AS IS" BASIS, |
| 9 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 10 | See the License for the specific language governing permissions and |
| 11 | limitations 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 | |
| 20 | namespace DB |
| 21 | { |
| 22 | |
| 23 | bool 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 | |