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
13#pragma once
14
15#include <optional>
16#include <Parsers/ASTAlterQuery.h>
17#include <Storages/LiveView/StorageLiveView.h>
18
19namespace DB
20{
21
22namespace ErrorCodes
23{
24 extern const int UNKNOWN_STORAGE;
25}
26
27struct 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
55class LiveViewCommands : public std::vector<LiveViewCommand>
56{
57public:
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