OmniSciDB  085a039ca4
 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 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 };
55 
57  public:
59  const DdlCommandData& ddl_data,
60  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
61 
62  ExecutionResult execute() override;
63 };
64 
66  public:
68  const DdlCommandData& ddl_data,
69  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
70 
71  ExecutionResult execute() 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() override;
88 };
89 
91  public:
93  const DdlCommandData& ddl_data,
94  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
95 
96  ExecutionResult execute() 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() override;
111 };
112 
114  public:
116  const DdlCommandData& ddl_data,
117  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
118  ExecutionResult execute() 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() override;
133 };
134 
136  public:
137  ShowTablesCommand(const DdlCommandData& ddl_data,
138  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
139 
140  ExecutionResult execute() override;
141 };
142 
144  public:
146  const DdlCommandData& ddl_data,
147  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
148 
149  ExecutionResult execute() override;
150 
151  private:
152  std::vector<std::string> getFilteredTableNames();
153 };
154 
156  public:
157  ShowDatabasesCommand(const DdlCommandData& ddl_data,
158  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
159 
160  ExecutionResult execute() override;
161 };
162 
164  public:
166  const DdlCommandData& ddl_data,
167  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
168 
169  ExecutionResult execute() override;
170 };
171 
173  public:
175  const DdlCommandData& ddl_data,
176  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
177 
178  ExecutionResult execute() override;
179 
180  private:
181  std::vector<std::string> getFilteredTableNames();
182 };
183 
185  public:
187  const DdlCommandData& ddl_data,
188  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
189 
190  ExecutionResult execute() override;
191 };
192 
193 class ShowRolesCommand : public DdlCommand {
194  public:
195  ShowRolesCommand(const DdlCommandData& ddl_data,
196  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
197 
198  ExecutionResult execute() override;
199 };
200 
202  public:
204  const DdlCommandData& ddl_data,
205  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
206 
207  ExecutionResult execute() override;
208 };
209 
211  public:
212  CreatePolicyCommand(const DdlCommandData& ddl_data,
213  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
214 
215  ExecutionResult execute() override;
216 };
217 
219  public:
220  ShowPoliciesCommand(const DdlCommandData& ddl_data,
221  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
222 
223  ExecutionResult execute() override;
224 };
225 
227  public:
228  DropPolicyCommand(const DdlCommandData& ddl_data,
229  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
230 
231  ExecutionResult execute() override;
232 };
233 
235  public:
236  ReassignOwnedCommand(const DdlCommandData& ddl_data,
237  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
238 
239  ExecutionResult execute() override;
240 
241  private:
242  std::string new_owner_;
243  std::set<std::string> old_owners_;
244 };
245 
247 enum class AggregationType { NONE, UNION };
248 
252 };
253 
255  public:
256  DdlCommandExecutor(const std::string& ddl_statement,
257  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
258 
266 
270  bool isShowUserSessions();
271 
275  bool isShowQueries();
276 
280  bool isShowCreateTable();
281 
285  bool isKillQuery();
286 
290  bool isAlterSystemClear();
291 
297  std::string returnCacheType();
298 
302  const std::string getTargetQuerySessionToKill();
303 
310 
314  const std::string commandStr();
315 
316  private:
317  std::string ddl_statement_; // incoming ddl_statement
318  std::string ddl_command_; // extracted from ddl_statement_
319  std::unique_ptr<DdlCommandData> ddl_data_; // container for parse data
320  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr_;
321 };
ExecutionResult execute() override
ShowForeignServersCommand(const DdlCommandData &ddl_data, std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)
ShowRolesCommand(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::string returnCacheType()
void alterOptions(const foreign_storage::ForeignTable &foreign_table)
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
ExecutionResult execute() 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() override
std::set< std::string > old_owners_
void setTableDetails(const std::string &table_name, TableDescriptor &td, const std::list< ColumnDescriptor > &columns)
const std::string getTargetQuerySessionToKill()
const DdlCommandData & ddl_data_
ExecutionResult execute() override
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
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)
ReassignOwnedCommand(const DdlCommandData &ddl_data, 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)
ShowPoliciesCommand(const DdlCommandData &ddl_data, std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)
std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr_
ExecutionLocation execution_location
ExecutionResult execute() override
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
ShowUserDetailsCommand(const DdlCommandData &ddl_data, std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)
ExecutionResult execute() override
RefreshForeignTablesCommand(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)
ExecutionResult execute() override