OmniSciDB  85c2d10cdc
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
DdlCommandExecutor.h
Go to the documentation of this file.
1 /*
2  * Copyright 2020 OmniSci, 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() = 0;
50 
51  protected:
53  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr_;
54  bool isDefaultServer(const std::string& server_name);
55 };
56 
58  public:
60  const DdlCommandData& ddl_data,
61  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
62 
63  ExecutionResult execute() override;
64 };
65 
67  public:
69  const DdlCommandData& ddl_data,
70  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
71 
72  ExecutionResult execute() 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() override;
89 };
90 
92  public:
94  const DdlCommandData& ddl_data,
95  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
96 
97  ExecutionResult execute() 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() override;
112 };
113 
115  public:
117  const DdlCommandData& ddl_data,
118  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
119  ExecutionResult execute() override;
120 
121  private:
122  void alterOptions(const foreign_storage::ForeignTable* foreign_table);
123  void renameTable(const foreign_storage::ForeignTable* foreign_table);
124  void renameColumn(const foreign_storage::ForeignTable* foreign_table);
125 };
126 
128  public:
130  const DdlCommandData& ddl_data,
131  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
132 
133  ExecutionResult execute() override;
134 };
135 
137  public:
138  ShowTablesCommand(const DdlCommandData& ddl_data,
139  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
140 
141  ExecutionResult execute() override;
142 };
143 
145  public:
147  const DdlCommandData& ddl_data,
148  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
149 
150  ExecutionResult execute() override;
151 
152  private:
153  std::vector<std::string> getFilteredTableNames();
154 };
155 
157  public:
158  ShowDatabasesCommand(const DdlCommandData& ddl_data,
159  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
160 
161  ExecutionResult execute() override;
162 };
163 
165  public:
167  const DdlCommandData& ddl_data,
168  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
169 
170  ExecutionResult execute() override;
171 
172  private:
173  std::vector<std::string> getFilteredTableNames();
174 };
175 
177  public:
179  const DdlCommandData& ddl_data,
180  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
181 
182  ExecutionResult execute() override;
183 };
184 
186 enum class AggregationType { NONE, UNION };
187 
191 };
192 
194  public:
195  DdlCommandExecutor(const std::string& ddl_statement,
196  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
197 
205 
209  bool isShowUserSessions();
210 
214  bool isShowQueries();
215 
219  bool isKillQuery();
220 
224  const std::string getTargetQuerySessionToKill();
225 
232 
236  const std::string commandStr();
237 
238  private:
239  std::string ddl_statement_; // incoming ddl_statement
240  std::string ddl_command_; // extracted from ddl_statement_
241  std::unique_ptr<DdlCommandData> ddl_data_; // container for parse data
242  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr_;
243 };
ShowForeignServersCommand(const DdlCommandData &ddl_data, std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)
ExecutionResult execute() override
AlterForeignServerCommand(const DdlCommandData &ddl_data, std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)
std::unique_ptr< DdlCommandData > ddl_data_
CreateForeignServerCommand(const DdlCommandData &ddl_data, std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)
ShowDatabasesCommand(const DdlCommandData &ddl_data, std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)
DropForeignTableCommand(const DdlCommandData &ddl_data, std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)
virtual ExecutionResult execute()=0
virtual std::string commandStr()=0
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)
void setTableDetails(const std::string &table_name, TableDescriptor &td, const std::list< ColumnDescriptor > &columns)
const std::string getTargetQuerySessionToKill()
const DdlCommandData & ddl_data_
AggregationType
const std::string commandStr()
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() override
DdlCommandData(const std::string &ddl_statement)
ExecutionResult execute() override
ExecutionResult execute() override
ExecutionResult execute() override
virtual ~DdlCommandData()
ExecutionResult execute() override
ExecutionResult execute() override
ExecutionLocation
void alterOptions(const foreign_storage::ForeignTable *foreign_table)
DistributedExecutionDetails getDistributedExecutionDetails()
ExecutionResult execute()
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)
std::vector< std::string > getFilteredTableNames()
ExecutionResult execute() override
ExecutionResult execute() override
DdlCommand(const DdlCommandData &ddl_data, std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)
void renameTable(const foreign_storage::ForeignTable *foreign_table)
bool isDefaultServer(const std::string &server_name)
std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr_
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)
ExecutionResult execute() override
ExecutionResult execute() override
ExecutionResult execute() override
RefreshForeignTablesCommand(const DdlCommandData &ddl_data, std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)