OmniSciDB  a5dc49c757
 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 
25 #include "Catalog/SessionInfo.h"
28 #include "Utils/DdlUtils.h"
29 
30 // This class should be subclassed to cache additional 'internal' data
31 // useful for the implementation, but will avoid being exposed in the header
33  public:
34  DdlCommandData(const std::string& ddl_statement) {}
35  virtual ~DdlCommandData() {}
36  virtual std::string commandStr() = 0;
37 };
38 
39 class DdlCommand {
40  public:
41  DdlCommand(const DdlCommandData& ddl_data,
42  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr)
43  : ddl_data_(ddl_data), session_ptr_(session_ptr) {}
44 
50  virtual ExecutionResult execute(bool read_only_mode) = 0;
51 
52  protected:
54  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr_;
55 };
56 
58  public:
60  const DdlCommandData& ddl_data,
61  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
62 
63  ExecutionResult execute(bool read_only_mode) override;
64 };
65 
67  public:
69  const DdlCommandData& ddl_data,
70  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
71 
72  ExecutionResult execute(bool read_only_mode) override;
73 
74  private:
76  void renameForeignServer();
80 };
81 
83  public:
85  const DdlCommandData& ddl_data,
86  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
87 
88  ExecutionResult execute(bool read_only_mode) override;
89 };
90 
92  public:
94  const DdlCommandData& ddl_data,
95  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
96 
97  ExecutionResult execute(bool read_only_mode) override;
98 
99  private:
100  void setTableDetails(const std::string& table_name,
101  TableDescriptor& td,
102  const std::list<ColumnDescriptor>& columns);
103  void setColumnDetails(std::list<ColumnDescriptor>& columns);
104 };
105 
107  public:
109  const DdlCommandData& ddl_data,
110  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
111  ExecutionResult execute(bool read_only_mode) override;
112 };
113 
115  public:
117  const DdlCommandData& ddl_data,
118  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
119 
120  ExecutionResult execute(bool read_only_mode) override;
121 
123 
124  private:
125  void alterColumn();
126 
128  const TypePairs& src_dst_cds);
129 
130  void cleanupRecoveryInfo(const TableDescriptor* td);
131 
132  void alterColumnTypes(const TableDescriptor* td, const TypePairs& src_dst_cds);
133 
135  const TypePairs& src_dst_cds);
136 
137  std::list<std::list<ColumnDescriptor>> prepareGeoColumns(const TableDescriptor* td,
138  const TypePairs& src_dst_cds);
139 
140  std::list<const ColumnDescriptor*> prepareColumns(const TableDescriptor* td,
141  const TypePairs& src_dst_cds);
142 
143  void alterColumns(const TableDescriptor* td, const TypePairs& src_dst_cds);
144 
145  void alterNonGeoColumnData(const TableDescriptor* td,
146  const std::list<const ColumnDescriptor*>& cds);
147 
148  void alterGeoColumnData(
149  const TableDescriptor* td,
150  const std::list<std::pair<const ColumnDescriptor*,
151  std::list<const ColumnDescriptor*>>>& geo_src_dst_cds);
152 
153  void clearInMemoryData(const TableDescriptor* td, const TypePairs& src_dst_cds);
154 
157 };
158 
160  public:
161  AlterTableCommand(const DdlCommandData& ddl_data,
162  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
163  ExecutionResult execute(bool read_only_mode) override;
164 };
165 
167  public:
169  const DdlCommandData& ddl_data,
170  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
171  ExecutionResult execute(bool read_only_mode) override;
172 
173  private:
174  void alterOptions(const foreign_storage::ForeignTable& foreign_table);
175  void renameTable(const foreign_storage::ForeignTable* foreign_table);
176  void renameColumn(const foreign_storage::ForeignTable* foreign_table);
177 };
178 
180  public:
182  const DdlCommandData& ddl_data,
183  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
184 
185  ExecutionResult execute(bool read_only_mode) override;
186 };
187 
189  public:
191  const DdlCommandData& ddl_data,
192  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
193 
194  ExecutionResult execute(bool read_only_mode) override;
195 
196  private:
197  std::string server_;
198 };
199 
201  public:
202  ShowTablesCommand(const DdlCommandData& ddl_data,
203  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
204 
205  ExecutionResult execute(bool read_only_mode) override;
206 };
207 
209  public:
211  const DdlCommandData& ddl_data,
212  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
213 
214  ExecutionResult execute(bool read_only_mode) override;
215 
216  private:
217  std::vector<std::string> getFilteredTableNames();
218 };
219 
221  public:
223  const DdlCommandData& ddl_data,
224  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
225 
226  ExecutionResult execute(bool read_only_mode) override;
227 };
228 
230  public:
231  ShowDatabasesCommand(const DdlCommandData& ddl_data,
232  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
233 
234  ExecutionResult execute(bool read_only_mode) override;
235 };
236 
238  public:
239  ShowFunctionsCommand(const DdlCommandData& ddl_data,
240  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
241 
242  ExecutionResult execute(bool read_only_mode) override;
243 };
244 
246  public:
248  const DdlCommandData& ddl_data,
249  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
250 
251  ExecutionResult execute(bool read_only_mode) override;
252 };
253 
255  public:
257  const DdlCommandData& ddl_data,
258  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
259 
260  ExecutionResult execute(bool read_only_mode) override;
261 };
262 
264  public:
266  const DdlCommandData& ddl_data,
267  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
268 
269  ExecutionResult execute(bool read_only_mode) override;
270 };
271 
273  public:
274  ShowModelsCommand(const DdlCommandData& ddl_data,
275  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
276 
277  ExecutionResult execute(bool read_only_mode) override;
278 };
279 
281  public:
283  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  std::vector<std::string> getFilteredModelNames();
290 };
291 
292 class AbstractMLModel;
293 class MLModelMetadata;
294 
296  public:
298  const DdlCommandData& ddl_data,
299  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
300 
301  ExecutionResult execute(bool read_only_mode) override;
302 
303  private:
304  std::vector<TargetMetaInfo> prepareLabelInfos() const;
305  std::pair<std::vector<double>, std::vector<std::vector<double>>> extractExtraMetadata(
306  std::shared_ptr<AbstractMLModel> model,
307  std::vector<TargetMetaInfo>& label_infos) const;
308 
309  std::vector<RelLogicalValues::RowValues> prepareLogicalValues(
310  const MLModelMetadata& model_metadata,
311  const std::vector<std::vector<std::string>>& cat_sub_features,
312  std::vector<double>& extra_metadata,
313  const std::vector<std::vector<double>>& eigenvectors,
314  const std::vector<int64_t>& inverse_permutations) const;
315 };
316 
318  public:
319  EvaluateModelCommand(const DdlCommandData& ddl_data,
320  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
321 
322  ExecutionResult execute(bool read_only_mode) override;
323 };
324 
326  public:
328  const DdlCommandData& ddl_data,
329  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
330 
331  ExecutionResult execute(bool read_only_mode) override;
332 
333  private:
334  std::vector<std::string> getFilteredTableNames();
335 };
336 
338  public:
340  const DdlCommandData& ddl_data,
341  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
342 
343  ExecutionResult execute(bool read_only_mode) override;
344 };
345 
346 class ShowRolesCommand : public DdlCommand {
347  public:
348  ShowRolesCommand(const DdlCommandData& ddl_data,
349  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
350 
351  ExecutionResult execute(bool read_only_mode) override;
352 };
353 
355  public:
357  const DdlCommandData& ddl_data,
358  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
359 
360  ExecutionResult execute(bool read_only_mode) override;
361 };
362 
364  public:
365  CreatePolicyCommand(const DdlCommandData& ddl_data,
366  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
367 
368  ExecutionResult execute(bool read_only_mode) override;
369 };
370 
372  public:
373  ShowPoliciesCommand(const DdlCommandData& ddl_data,
374  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
375 
376  ExecutionResult execute(bool read_only_mode) override;
377 };
378 
380  public:
381  DropPolicyCommand(const DdlCommandData& ddl_data,
382  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
383 
384  ExecutionResult execute(bool read_only_mode) override;
385 };
386 
388  public:
389  AlterDatabaseCommand(const DdlCommandData& ddl_data,
390  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
391 
392  ExecutionResult execute(bool read_only_mode) override;
393 
394  private:
395  void changeOwner();
396  void rename();
397 };
398 
400  public:
401  ReassignOwnedCommand(const DdlCommandData& ddl_data,
402  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
403 
404  ExecutionResult execute(bool read_only_mode) override;
405 
406  private:
407  std::string new_owner_;
408  std::set<std::string> old_owners_;
409  bool all_;
410 };
411 
413 enum class AggregationType { NONE, UNION };
414 
418 };
419 
421  public:
422  DdlCommandExecutor(const std::string& ddl_statement,
423  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
424 
431  ExecutionResult execute(bool read_only_mode);
432 
436  bool isShowUserSessions() const;
437 
441  bool isShowQueries() const;
442 
446  bool isKillQuery() const;
447 
451  bool isAlterSystemClear() const;
452 
456  bool isAlterSessionSet() const;
457 
461  std::string returnCacheType() const;
462 
467 
472  std::string returnQueueAction() const;
473 
477  const std::string getTargetQuerySessionToKill() const;
478 
485 
489  const std::string commandStr() const;
490 
494  std::pair<std::string, std::string> getSessionParameter() const;
495 
496  private:
497  std::string ddl_statement_; // incoming ddl_statement
498  std::string ddl_command_; // extracted from ddl_statement_
499  std::unique_ptr<DdlCommandData> ddl_data_; // container for parse data
500  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr_;
501 };
ExecutionResult execute(bool read_only_mode) override
ShowForeignServersCommand(const DdlCommandData &ddl_data, std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)
void alterGeoColumnData(const TableDescriptor *td, const std::list< std::pair< const ColumnDescriptor *, std::list< const ColumnDescriptor * >>> &geo_src_dst_cds)
ExecutionResult execute(bool read_only_mode) override
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
std::vector< std::string > getFilteredModelNames()
AlterForeignServerCommand(const DdlCommandData &ddl_data, std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)
void cleanupRecoveryInfo(const TableDescriptor *td)
std::pair< std::vector< double >, std::vector< std::vector< double > > > extractExtraMetadata(std::shared_ptr< AbstractMLModel > model, std::vector< TargetMetaInfo > &label_infos) const
AlterTableAlterColumnCommand(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
void clearInMemoryData(const TableDescriptor *td, const TypePairs &src_dst_cds)
ExecutionResult execute(bool read_only_mode) override
ExecutionResult execute(bool read_only_mode) override
ExecutionResult execute(bool read_only_mode) override
ExecutionResult execute(bool read_only_mode) override
virtual ExecutionResult execute(bool read_only_mode)=0
AlterTableAlterColumnCommandRecoveryMgr::RecoveryInfo recovery_info_
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)
ExecutionResult execute(bool read_only_mode) override
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
void alterColumns(const TableDescriptor *td, const TypePairs &src_dst_cds)
std::pair< std::string, std::string > getSessionParameter() const
DistributedExecutionDetails getDistributedExecutionDetails() const
EvaluateModelCommand(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
std::set< std::string > old_owners_
void alterNonGeoColumnData(const TableDescriptor *td, const std::list< const ColumnDescriptor * > &cds)
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
ShowModelFeatureDetailsCommand(const DdlCommandData &ddl_data, std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)
std::vector< TargetMetaInfo > prepareLabelInfos() const
void populateAndWriteRecoveryInfo(const TableDescriptor *td, const TypePairs &src_dst_cds)
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)
std::list< const ColumnDescriptor * > prepareColumns(const TableDescriptor *td, const TypePairs &src_dst_cds)
AlterDatabaseCommand(const DdlCommandData &ddl_data, std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)
bool isShowUserSessions() const
ExecutionResult execute(bool read_only_mode) override
specifies the content in-memory of a row in the column metadata table
void collectExpectedCatalogChanges(const TableDescriptor *td, const TypePairs &src_dst_cds)
virtual ~DdlCommandData()
void alterColumnTypes(const TableDescriptor *td, const TypePairs &src_dst_cds)
std::list< std::list< ColumnDescriptor > > prepareGeoColumns(const TableDescriptor *td, const TypePairs &src_dst_cds)
std::list< std::pair< const ColumnDescriptor *, ColumnDescriptor * >> TypePairs
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)
ShowModelDetailsCommand(const DdlCommandData &ddl_data, std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)
ExecutionResult execute(bool read_only_mode)
ExecutionResult execute(bool read_only_mode) override
std::string returnQueueAction() const
AlterTableAlterColumnCommandRecoveryMgr recovery_mgr_
AlterTableCommand(const DdlCommandData &ddl_data, std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)
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()
ExecutionResult execute(bool read_only_mode) override
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)
alter_column_shared::TypePairs TypePairs
ExecutionResult execute(bool read_only_mode) override
ExecutionResult execute(bool read_only_mode) override
std::vector< RelLogicalValues::RowValues > prepareLogicalValues(const MLModelMetadata &model_metadata, const std::vector< std::vector< std::string >> &cat_sub_features, std::vector< double > &extra_metadata, const std::vector< std::vector< double >> &eigenvectors, const std::vector< int64_t > &inverse_permutations) const
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
bool isAlterSystemControlExecutorQueue() const
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
ShowModelsCommand(const DdlCommandData &ddl_data, std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)
ShowTableFunctionsCommand(const DdlCommandData &ddl_data, std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)