OmniSciDB  a5dc49c757
 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 {
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  Calcite() {}
75  // sql_string may differ from what is in query_state due to legacy_syntax option.
76  TPlanResult process(query_state::QueryStateProxy,
77  std::string sql_string,
78  const TQueryParsingOption& query_parsing_option,
79  const TOptimizationOption& optimization_option,
80  const std::string& calcite_session_id = "");
81  void checkAccessedObjectsPrivileges(query_state::QueryStateProxy query_state_prox,
82  TPlanResult plan) const;
83  std::vector<TCompletionHint> getCompletionHints(
84  const Catalog_Namespace::SessionInfo& session_info,
85  const std::vector<std::string>& visible_tables,
86  const std::string sql_string,
87  const int cursor);
88  std::string getExtensionFunctionWhitelist();
89  std::string getUserDefinedFunctionWhitelist();
90  virtual void updateMetadata(std::string catalog, std::string table);
91  void close_calcite_server(bool log = true);
92  virtual ~Calcite();
93  std::string getRuntimeExtensionFunctionWhitelist();
94  void setRuntimeExtensionFunctions(const std::vector<TUserDefinedFunction>& udfs,
95  const std::vector<TUserDefinedTableFunction>& udtfs,
96  bool isruntime = true);
97  static std::string const getInternalSessionProxyUserName() { return kCalciteUserName; }
98  static std::string const getInternalSessionProxyPassword() {
99  return kCalciteUserPassword;
100  }
101  TQueryParsingOption getCalciteQueryParsingOption(bool legacy_syntax,
102  bool is_explain,
103  bool check_privileges,
104  bool is_explain_detail);
105  TOptimizationOption getCalciteOptimizationOption(
106  bool is_view_optimize,
107  bool enable_watchdog,
108  const std::vector<TFilterPushDownInfo>& filter_push_down_info,
109  bool distributed_mode);
110 
111  private:
112  void init(const int db_port,
113  const int port,
114  const std::string& data_dir,
115  const size_t calcite_max_mem,
116  const std::string& udf_filename);
117  void runServer(const int db_port,
118  const int port,
119  const std::string& data_dir,
120  const size_t calcite_max_mem,
121  const std::string& udf_filename);
122  TPlanResult processImpl(query_state::QueryStateProxy,
123  std::string sql_string,
124  const TQueryParsingOption& query_parsing_option,
125  const TOptimizationOption& optimization_option,
126  const std::string& calcite_session_id);
127  std::vector<std::string> get_db_objects(const std::string ra);
128  void inner_close_calcite_server(bool log);
129  std::pair<std::shared_ptr<CalciteServerClient>, std::shared_ptr<TTransport>> getClient(
130  int port);
131 
132  int ping(int retry_num = 0, int max_retry = 50);
133 
134  std::shared_ptr<ThriftClientConnection> connMgr_;
137  bool service_keepalive_ = true;
138  int remote_calcite_port_ = -1;
139  std::string ssl_trust_store_;
140  std::string ssl_trust_password_;
141  std::string ssl_key_file_;
142  std::string ssl_keystore_;
144  std::string ssl_ca_file_;
145  std::string db_config_file_;
146  std::once_flag shutdown_once_flag_;
147 };
std::string db_config_file_
Definition: Calcite.h:145
std::once_flag shutdown_once_flag_
Definition: Calcite.h:146
std::string ssl_key_file_
Definition: Calcite.h:141
Calcite()
Definition: Calcite.h:74
std::string ssl_keystore_
Definition: Calcite.h:142
static std::string const getInternalSessionProxyUserName()
Definition: Calcite.h:97
static std::string const getInternalSessionProxyPassword()
Definition: Calcite.h:98
std::string ssl_keystore_password_
Definition: Calcite.h:143
std::shared_ptr< ThriftClientConnection > connMgr_
Definition: Calcite.h:134
std::string ssl_trust_store_
Definition: Calcite.h:139
void init(LogOptions const &log_opts)
Definition: Logger.cpp:364
constexpr char const * kCalciteUserPassword
Definition: Calcite.h:40
std::string ssl_ca_file_
Definition: Calcite.h:144
size_t service_timeout_
Definition: Calcite.h:136
bool server_available_
Definition: Calcite.h:135
std::string ssl_trust_password_
Definition: Calcite.h:140
constexpr char const * kCalciteUserName
Definition: Calcite.h:39