OmniSciDB  2e3a973ef4
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 #include "rapidjson/document.h"
22 
23 #include "Catalog/SessionInfo.h"
24 #include "gen-cpp/omnisci_types.h"
25 
27 #include "Catalog/SessionInfo.h"
29 #include "Utils/DdlUtils.h"
30 #include "gen-cpp/omnisci_types.h"
31 
32 class DdlCommand {
33  public:
34  DdlCommand(const rapidjson::Value& ddl_payload,
35  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr)
36  : ddl_payload_(ddl_payload), session_ptr_(session_ptr) {}
37 
43  virtual void execute(TQueryResult& _return) = 0;
44 
45  protected:
46  const rapidjson::Value& ddl_payload_;
47  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr_;
48  bool isDefaultServer(const std::string& server_name);
49 };
50 
52  public:
54  const rapidjson::Value& ddl_payload,
55  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
56 
57  void execute(TQueryResult& _return) override;
58 };
59 
61  public:
63  const rapidjson::Value& ddl_payload,
64  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
65 
66  void execute(TQueryResult& _return) override;
67 
68  private:
69  void changeForeignServerOwner();
70  void renameForeignServer();
71  void setForeignServerOptions();
72  void setForeignServerDataWrapper();
73  bool hasAlterServerPrivileges();
74 };
75 
77  public:
79  const rapidjson::Value& ddl_payload,
80  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
81 
82  void execute(TQueryResult& _return) override;
83 };
84 
86  public:
87  JsonColumnSqlType(const rapidjson::Value& data_type)
88  : ddl_utils::SqlType(getSqlType(data_type),
89  getParam1(data_type),
90  getParam2(data_type),
91  isArray(data_type),
92  getArraySize(data_type)) {}
93 
94  private:
95  static SQLTypes getSqlType(const rapidjson::Value& data_type);
96  static SQLTypes getSqlType(const std::string& type);
97  static int getParam1(const rapidjson::Value& data_type);
98  static int getParam2(const rapidjson::Value& data_type);
99  static bool isArray(const rapidjson::Value& data_type);
100  static int getArraySize(const rapidjson::Value& data_type);
101 };
102 
104  public:
105  JsonColumnEncoding(const rapidjson::Value& data_type)
106  : ddl_utils::Encoding(getEncodingName(data_type), getEncodingParam(data_type)) {}
107 
108  private:
109  static std::string* getEncodingName(const rapidjson::Value& data_type);
110  static int getEncodingParam(const rapidjson::Value& data_type);
111 };
112 
114  public:
116  const rapidjson::Value& ddl_payload,
117  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
118 
119  void execute(TQueryResult& _return) override;
120 
121  private:
122  void setTableDetails(const std::string& table_name,
123  TableDescriptor& td,
124  const size_t column_count);
125  void setColumnDetails(std::list<ColumnDescriptor>& columns);
126  void setRefreshOptions(foreign_storage::ForeignTable& foreign_table);
127 };
128 
130  public:
132  const rapidjson::Value& ddl_payload,
133  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
134  void execute(TQueryResult& _return) override;
135 };
136 
138  public:
140  const rapidjson::Value& ddl_payload,
141  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
142  void execute(TQueryResult& _return) override;
143 };
144 
146  public:
147  ShowTablesCommand(const rapidjson::Value& ddl_payload,
148  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
149 
150  void execute(TQueryResult& _return) override;
151 };
152 
154  public:
155  ShowDatabasesCommand(const rapidjson::Value& ddl_payload,
156  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
157 
158  void execute(TQueryResult& _return) override;
159 };
160 
162  public:
164  const rapidjson::Value& ddl_payload,
165  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
166 
167  void execute(TQueryResult& _return) override;
168 };
169 
171  public:
172  DdlCommandExecutor(const std::string& ddl_statement,
173  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
174 
181  void execute(TQueryResult& _return);
182 
186  bool isShowUserSessions();
187 
191  bool isShowQueries();
192 
196  bool isKillQuery();
197 
201  const std::string getTargetQuerySessionToKill();
202 
203  private:
204  rapidjson::Document ddl_query_;
205  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr_;
206 };
SQLTypes
Definition: sqltypes.h:40
virtual void execute(TQueryResult &_return)=0
JsonColumnSqlType(const rapidjson::Value &data_type)
DdlCommand(const rapidjson::Value &ddl_payload, std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)
std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr_
rapidjson::Document ddl_query_
bool isDefaultServer(const std::string &server_name)
const rapidjson::Value & ddl_payload_
std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr_
specifies the content in-memory of a row in the table metadata table
JsonColumnEncoding(const rapidjson::Value &data_type)