OmniSciDB  ca0c39ec8f
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DdlCommandExecutor.h
Go to the documentation of this file.
1 /*
2  * Copyright 2022 HEAVY.AI, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <string>
20 
21 // Note: avoid adding #include(s) that require thrift
22 
24 #include "Catalog/SessionInfo.h"
27 #include "Utils/DdlUtils.h"
28 
29 // This class should be subclassed to cache additional 'internal' data
30 // useful for the implementation, but will avoid being exposed in the header
32  public:
33  DdlCommandData(const std::string& ddl_statement) {}
34  virtual ~DdlCommandData() {}
35  virtual std::string commandStr() = 0;
36 };
37 
38 class DdlCommand {
39  public:
40  DdlCommand(const DdlCommandData& ddl_data,
41  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr)
42  : ddl_data_(ddl_data), session_ptr_(session_ptr) {}
43 
49  virtual ExecutionResult execute(bool read_only_mode) = 0;
50 
51  protected:
53  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr_;
54 };
55 
57  public:
59  const DdlCommandData& ddl_data,
60  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
61 
62  ExecutionResult execute(bool read_only_mode) override;
63 };
64 
66  public:
68  const DdlCommandData& ddl_data,
69  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
70 
71  ExecutionResult execute(bool read_only_mode) override;
72 
73  private:
75  void renameForeignServer();
79 };
80 
82  public:
84  const DdlCommandData& ddl_data,
85  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
86 
87  ExecutionResult execute(bool read_only_mode) override;
88 };
89 
91  public:
93  const DdlCommandData& ddl_data,
94  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
95 
96  ExecutionResult execute(bool read_only_mode) override;
97 
98  private:
99  void setTableDetails(const std::string& table_name,
100  TableDescriptor& td,
101  const std::list<ColumnDescriptor>& columns);
102  void setColumnDetails(std::list<ColumnDescriptor>& columns);
103 };
104 
106  public:
108  const DdlCommandData& ddl_data,
109  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
110  ExecutionResult execute(bool read_only_mode) override;
111 };
112 
114  public:
116  const DdlCommandData& ddl_data,
117  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
118  ExecutionResult execute(bool read_only_mode) override;
119 
120  private:
121  void alterOptions(const foreign_storage::ForeignTable& foreign_table);
122  void renameTable(const foreign_storage::ForeignTable* foreign_table);
123  void renameColumn(const foreign_storage::ForeignTable* foreign_table);
124 };
125 
127  public:
129  const DdlCommandData& ddl_data,
130  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
131 
132  ExecutionResult execute(bool read_only_mode) override;
133 };
134 
136  public:
138  const DdlCommandData& ddl_data,
139  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
140 
141  ExecutionResult execute(bool read_only_mode) override;
142 
143  private:
144  std::string server_;
145 };
146 
148  public:
149  ShowTablesCommand(const DdlCommandData& ddl_data,
150  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
151 
152  ExecutionResult execute(bool read_only_mode) override;
153 };
154 
156  public:
158  const DdlCommandData& ddl_data,
159  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
160 
161  ExecutionResult execute(bool read_only_mode) override;
162 
163  private:
164  std::vector<std::string> getFilteredTableNames();
165 };
166 
168  public:
170  const DdlCommandData& ddl_data,
171  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
172 
173  ExecutionResult execute(bool read_only_mode) override;
174 };
175 
177  public:
178  ShowDatabasesCommand(const DdlCommandData& ddl_data,
179  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
180 
181  ExecutionResult execute(bool read_only_mode) override;
182 };
183 
185  public:
186  ShowFunctionsCommand(const DdlCommandData& ddl_data,
187  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
188 
189  ExecutionResult execute(bool read_only_mode) override;
190 };
191 
193  public:
195  const DdlCommandData& ddl_data,
196  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
197 
198  ExecutionResult execute(bool read_only_mode) override;
199 };
200 
202  public:
204  const DdlCommandData& ddl_data,
205  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
206 
207  ExecutionResult execute(bool read_only_mode) override;
208 };
209 
211  public:
213  const DdlCommandData& ddl_data,
214  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
215 
216  ExecutionResult execute(bool read_only_mode) override;
217 };
218 
220  public:
222  const DdlCommandData& ddl_data,
223  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
224 
225  ExecutionResult execute(bool read_only_mode) override;
226 
227  private:
228  std::vector<std::string> getFilteredTableNames();
229 };
230 
232  public:
234  const DdlCommandData& ddl_data,
235  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
236 
237  ExecutionResult execute(bool read_only_mode) override;
238 };
239 
240 class ShowRolesCommand : public DdlCommand {
241  public:
242  ShowRolesCommand(const DdlCommandData& ddl_data,
243  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
244 
245  ExecutionResult execute(bool read_only_mode) override;
246 };
247 
249  public:
251  const DdlCommandData& ddl_data,
252  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
253 
254  ExecutionResult execute(bool read_only_mode) override;
255 };
256 
258  public:
259  CreatePolicyCommand(const DdlCommandData& ddl_data,
260  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
261 
262  ExecutionResult execute(bool read_only_mode) override;
263 };
264 
266  public:
267  ShowPoliciesCommand(const DdlCommandData& ddl_data,
268  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
269 
270  ExecutionResult execute(bool read_only_mode) override;
271 };
272 
274  public:
275  DropPolicyCommand(const DdlCommandData& ddl_data,
276  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
277 
278  ExecutionResult execute(bool read_only_mode) override;
279 };
280 
282  public:
283  AlterDatabaseCommand(const DdlCommandData& ddl_data,
284  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
285 
286  ExecutionResult execute(bool read_only_mode) override;
287 
288  private:
289  void changeOwner();
290  void rename();
291 };
292 
294  public:
295  ReassignOwnedCommand(const DdlCommandData& ddl_data,
296  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
297 
298  ExecutionResult execute(bool read_only_mode) override;
299 
300  private:
301  std::string new_owner_;
302  std::set<std::string> old_owners_;
303 };
304 
306 enum class AggregationType { NONE, UNION };
307 
311 };
312 
314  public:
315  DdlCommandExecutor(const std::string& ddl_statement,
316  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
317 
324  ExecutionResult execute(bool read_only_mode);
325 
329  bool isShowUserSessions() const;
330 
334  bool isShowQueries() const;
335 
339  bool isKillQuery() const;
340 
344  bool isAlterSystemClear() const;
345 
349  bool isAlterSessionSet() const;
350 
354  std::string returnCacheType() const;
355 
359  const std::string getTargetQuerySessionToKill() const;
360 
367 
371  const std::string commandStr() const;
372 
376  std::pair<std::string, std::string> getSessionParameter() const;
377 
378  private:
379  std::string ddl_statement_; // incoming ddl_statement
380  std::string ddl_command_; // extracted from ddl_statement_
381  std::unique_ptr<DdlCommandData> ddl_data_; // container for parse data
382  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr_;
383 };
ShowForeignServersCommand(const DdlCommandData &ddl_data, std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)
ExecutionResult execute(bool read_only_mode) override
ShowRolesCommand(const DdlCommandData &ddl_data, std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)
ExecutionResult execute(bool read_only_mode) override
AlterForeignServerCommand(const DdlCommandData &ddl_data, std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)
void alterOptions(const foreign_storage::ForeignTable &foreign_table)
const std::string getTargetQuerySessionToKill() const
ShowCreateTableCommand(const DdlCommandData &ddl_data, std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)
ShowCreateServerCommand(const DdlCommandData &ddl_data, std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)
std::unique_ptr< DdlCommandData > ddl_data_
const std::string commandStr() const
ExecutionResult execute(bool read_only_mode) override
ExecutionResult execute(bool read_only_mode) override
virtual ExecutionResult execute(bool read_only_mode)=0
ExecutionResult execute(bool read_only_mode) override
CreateForeignServerCommand(const DdlCommandData &ddl_data, std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)
ExecutionResult execute(bool read_only_mode) override
ShowDatabasesCommand(const DdlCommandData &ddl_data, std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)
ExecutionResult execute(bool read_only_mode) override
ExecutionResult execute(bool read_only_mode) override
DropForeignTableCommand(const DdlCommandData &ddl_data, std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)
virtual std::string commandStr()=0
ExecutionResult execute(bool read_only_mode) override
CreatePolicyCommand(const DdlCommandData &ddl_data, std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)
CreateForeignTableCommand(const DdlCommandData &ddl_data, std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)
ShowTablesCommand(const DdlCommandData &ddl_data, std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)
ShowDiskCacheUsageCommand(const DdlCommandData &ddl_data, std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)
DropPolicyCommand(const DdlCommandData &ddl_data, std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)
ExecutionResult execute(bool read_only_mode) override
std::pair< std::string, std::string > getSessionParameter() const
DistributedExecutionDetails getDistributedExecutionDetails() const
ExecutionResult execute(bool read_only_mode) override
ExecutionResult execute(bool read_only_mode) override
std::set< std::string > old_owners_
ExecutionResult execute(bool read_only_mode) override
void setTableDetails(const std::string &table_name, TableDescriptor &td, const std::list< ColumnDescriptor > &columns)
bool isAlterSystemClear() const
ExecutionResult execute(bool read_only_mode) override
const DdlCommandData & ddl_data_
AggregationType
ExecutionResult execute(bool read_only_mode) override
ShowTableDetailsCommand(const DdlCommandData &ddl_data, std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)
void setColumnDetails(std::list< ColumnDescriptor > &columns)
DropForeignServerCommand(const DdlCommandData &ddl_data, std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)
ExecutionResult execute(bool read_only_mode) override
DdlCommandData(const std::string &ddl_statement)
AlterDatabaseCommand(const DdlCommandData &ddl_data, std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)
bool isShowUserSessions() const
ExecutionResult execute(bool read_only_mode) override
virtual ~DdlCommandData()
ExecutionResult execute(bool read_only_mode) override
ExecutionLocation
ExecutionResult execute(bool read_only_mode) override
bool isAlterSessionSet() const
std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr_
std::vector< std::string > getFilteredTableNames()
DdlCommandExecutor(const std::string &ddl_statement, std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)
ExecutionResult execute(bool read_only_mode)
ExecutionResult execute(bool read_only_mode) override
ExecutionResult execute(bool read_only_mode) override
ReassignOwnedCommand(const DdlCommandData &ddl_data, std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)
std::vector< std::string > getFilteredTableNames()
std::string returnCacheType() const
DdlCommand(const DdlCommandData &ddl_data, std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)
void renameTable(const foreign_storage::ForeignTable *foreign_table)
ShowFunctionsCommand(const DdlCommandData &ddl_data, std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)
ExecutionResult execute(bool read_only_mode) override
ExecutionResult execute(bool read_only_mode) override
ShowPoliciesCommand(const DdlCommandData &ddl_data, std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)
std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr_
ExecutionResult execute(bool read_only_mode) override
ExecutionLocation execution_location
AlterForeignTableCommand(const DdlCommandData &ddl_data, std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)
void renameColumn(const foreign_storage::ForeignTable *foreign_table)
ShowRuntimeFunctionsCommand(const DdlCommandData &ddl_data, std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)
ShowUserDetailsCommand(const DdlCommandData &ddl_data, std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)
ShowRuntimeTableFunctionsCommand(const DdlCommandData &ddl_data, std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)
RefreshForeignTablesCommand(const DdlCommandData &ddl_data, std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)
ExecutionResult execute(bool read_only_mode) override
ShowTableFunctionsCommand(const DdlCommandData &ddl_data, std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)