| 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 | #pragma once |
| 13 | |
| 14 | #include <Parsers/ASTQueryWithTableAndOutput.h> |
| 15 | #include <Common/quoteString.h> |
| 16 | |
| 17 | |
| 18 | namespace DB |
| 19 | { |
| 20 | |
| 21 | class ASTWatchQuery : public ASTQueryWithTableAndOutput |
| 22 | { |
| 23 | |
| 24 | public: |
| 25 | ASTPtr limit_length; |
| 26 | bool is_watch_events; |
| 27 | |
| 28 | ASTWatchQuery() = default; |
| 29 | String getID(char) const override { return "WatchQuery_"+ database + "_"+ table; } |
| 30 | |
| 31 | ASTPtr clone() const override |
| 32 | { |
| 33 | std::shared_ptr<ASTWatchQuery> res = std::make_shared<ASTWatchQuery>(*this); |
| 34 | res->children.clear(); |
| 35 | cloneOutputOptions(*res); |
| 36 | return res; |
| 37 | } |
| 38 | |
| 39 | protected: |
| 40 | void formatQueryImpl(const FormatSettings & s, FormatState & state, FormatStateStacked frame) const override |
| 41 | { |
| 42 | std::string indent_str = s.one_line ? "": std::string(4 * frame.indent, ' '); |
| 43 | |
| 44 | s.ostr << (s.hilite ? hilite_keyword : "") << "WATCH"<< " "<< (s.hilite ? hilite_none : "") |
| 45 | << (!database.empty() ? backQuoteIfNeed(database) + ".": "") << backQuoteIfNeed(table); |
| 46 | |
| 47 | if (is_watch_events) |
| 48 | { |
| 49 | s.ostr << " "<< (s.hilite ? hilite_keyword : "") << "EVENTS"<< (s.hilite ? hilite_none : ""); |
| 50 | } |
| 51 | |
| 52 | if (limit_length) |
| 53 | { |
| 54 | s.ostr << (s.hilite ? hilite_keyword : "") << s.nl_or_ws << indent_str << "LIMIT "<< (s.hilite ? hilite_none : ""); |
| 55 | limit_length->formatImpl(s, state, frame); |
| 56 | } |
| 57 | } |
| 58 | }; |
| 59 | |
| 60 | } |
| 61 |