OmniSciDB  c0231cc57d
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Calcite.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 
23 #pragma once
24 
25 #include "gen-cpp/calciteserver_types.h"
26 #include "gen-cpp/extension_functions_types.h"
27 
28 // gen-cpp/calciteserver_types.h > thrift/Thrift.h >
29 // thrift/transport/PlatformSocket.h > winsock2.h > windows.h
31 
32 #include <mutex>
33 #include <string>
34 #include <vector>
35 
36 using namespace apache::thrift::transport;
37 
38 namespace {
39 constexpr char const* kCalciteUserName = "calcite";
40 constexpr char const* kCalciteUserPassword = "HyperInteractive";
41 } // namespace
42 
43 class CalciteServerClient;
44 
45 namespace Catalog_Namespace {
46 class SessionInfo;
47 } // namespace Catalog_Namespace
48 
49 namespace query_state {
50 class QueryStateProxy;
51 }
52 
53 struct SystemParameters;
54 
56 
57 // Forward declares for Thrift-generated classes
58 class TFilterPushDownInfo;
59 class TPlanResult;
60 class TCompletionHint;
61 
62 class Calcite final {
63  public:
64  Calcite(const int db_port,
65  const int port,
66  const std::string& data_dir,
67  const size_t calcite_max_mem,
68  const size_t service_timeout,
69  const bool service_keepalive,
70  const std::string& udf_filename = "");
71  Calcite(const SystemParameters& db_parameters,
72  const std::string& data_dir,
73  const std::string& udf_filename = "");
74  // sql_string may differ from what is in query_state due to legacy_syntax option.
75  TPlanResult process(query_state::QueryStateProxy,
76  std::string sql_string,
77  const TQueryParsingOption& query_parsing_option,
78  const TOptimizationOption& optimization_option,
79  const std::string& calcite_session_id = "");
80  void checkAccessedObjectsPrivileges(query_state::QueryStateProxy query_state_prox,
81  TPlanResult plan) const;
82  std::vector<TCompletionHint> getCompletionHints(
83  const Catalog_Namespace::SessionInfo& session_info,
84  const std::vector<std::string>& visible_tables,
85  const std::string sql_string,
86  const int cursor);
87  std::string getExtensionFunctionWhitelist();
88  std::string getUserDefinedFunctionWhitelist();
89  void updateMetadata(std::string catalog, std::string table);
90  void close_calcite_server(bool log = true);
91  ~Calcite();
92  std::string getRuntimeExtensionFunctionWhitelist();
93  void setRuntimeExtensionFunctions(const std::vector<TUserDefinedFunction>& udfs,
94  const std::vector<TUserDefinedTableFunction>& udtfs,
95  bool isruntime = true);
96  static std::string const getInternalSessionProxyUserName() { return kCalciteUserName; }
97  static std::string const getInternalSessionProxyPassword() {
98  return kCalciteUserPassword;
99  }
100  TQueryParsingOption getCalciteQueryParsingOption(bool legacy_syntax,
101  bool is_explain,
102  bool check_privileges);
103  TOptimizationOption getCalciteOptimizationOption(
104  bool is_view_optimize,
105  bool enable_watchdog,
106  const std::vector<TFilterPushDownInfo>& filter_push_down_info,
107  bool distributed_mode);
108 
109  private:
110  void init(const int db_port,
111  const int port,
112  const std::string& data_dir,
113  const size_t calcite_max_mem,
114  const std::string& udf_filename);
115  void runServer(const int db_port,
116  const int port,
117  const std::string& data_dir,
118  const size_t calcite_max_mem,
119  const std::string& udf_filename);
120  TPlanResult processImpl(query_state::QueryStateProxy,
121  std::string sql_string,
122  const TQueryParsingOption& query_parsing_option,
123  const TOptimizationOption& optimization_option,
124  const std::string& calcite_session_id);
125  std::vector<std::string> get_db_objects(const std::string ra);
126  void inner_close_calcite_server(bool log);
127  std::pair<std::shared_ptr<CalciteServerClient>, std::shared_ptr<TTransport>> getClient(
128  int port);
129 
130  int ping(int retry_num = 0, int max_retry = 50);
131 
132  std::shared_ptr<ThriftClientConnection> connMgr_;
135  bool service_keepalive_ = true;
136  int remote_calcite_port_ = -1;
137  std::string ssl_trust_store_;
138  std::string ssl_trust_password_;
139  std::string ssl_key_file_;
140  std::string ssl_keystore_;
142  std::string ssl_ca_file_;
143  std::string db_config_file_;
144  std::once_flag shutdown_once_flag_;
145 };
std::string db_config_file_
Definition: Calcite.h:143
std::once_flag shutdown_once_flag_
Definition: Calcite.h:144
std::string ssl_key_file_
Definition: Calcite.h:139
std::string ssl_keystore_
Definition: Calcite.h:140
static std::string const getInternalSessionProxyUserName()
Definition: Calcite.h:96
static std::string const getInternalSessionProxyPassword()
Definition: Calcite.h:97
std::string ssl_keystore_password_
Definition: Calcite.h:141
std::shared_ptr< ThriftClientConnection > connMgr_
Definition: Calcite.h:132
std::string ssl_trust_store_
Definition: Calcite.h:137
void init(LogOptions const &log_opts)
Definition: Logger.cpp:308
constexpr char const * kCalciteUserPassword
Definition: Calcite.h:40
std::string ssl_ca_file_
Definition: Calcite.h:142
size_t service_timeout_
Definition: Calcite.h:134
bool server_available_
Definition: Calcite.h:133
std::string ssl_trust_password_
Definition: Calcite.h:138
constexpr char const * kCalciteUserName
Definition: Calcite.h:39