| 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 | |
| 13 | #pragma once |
| 14 | |
| 15 | #include <optional> |
| 16 | #include <Parsers/ASTAlterQuery.h> |
| 17 | #include <Storages/LiveView/StorageLiveView.h> |
| 18 | |
| 19 | namespace DB |
| 20 | { |
| 21 | |
| 22 | namespace ErrorCodes |
| 23 | { |
| 24 | extern const int UNKNOWN_STORAGE; |
| 25 | } |
| 26 | |
| 27 | struct LiveViewCommand |
| 28 | { |
| 29 | enum Type |
| 30 | { |
| 31 | REFRESH |
| 32 | }; |
| 33 | |
| 34 | Type type; |
| 35 | |
| 36 | ASTPtr values; |
| 37 | |
| 38 | static LiveViewCommand refresh(const ASTPtr & values) |
| 39 | { |
| 40 | LiveViewCommand res; |
| 41 | res.type = REFRESH; |
| 42 | res.values = values; |
| 43 | return res; |
| 44 | } |
| 45 | |
| 46 | static std::optional<LiveViewCommand> parse(ASTAlterCommand * command) |
| 47 | { |
| 48 | if (command->type == ASTAlterCommand::LIVE_VIEW_REFRESH) |
| 49 | return refresh(command->values); |
| 50 | return {}; |
| 51 | } |
| 52 | }; |
| 53 | |
| 54 | |
| 55 | class LiveViewCommands : public std::vector<LiveViewCommand> |
| 56 | { |
| 57 | public: |
| 58 | void validate(const IStorage & table) |
| 59 | { |
| 60 | if (!empty() && !dynamic_cast<const StorageLiveView *>(&table)) |
| 61 | throw Exception("Wrong storage type. Must be StorageLiveView", DB::ErrorCodes::UNKNOWN_STORAGE); |
| 62 | } |
| 63 | }; |
| 64 | |
| 65 | } |
| 66 |