OmniSciDB  6686921089
 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 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 /*
18  * File: Calcite.h
19  * Author: michael
20  *
21  * Created on November 23, 2015, 9:33 AM
22  */
23 
24 #pragma once
25 
26 #include "gen-cpp/extension_functions_types.h"
27 
28 #include <thrift/transport/TTransport.h>
29 
30 #include <mutex>
31 #include <string>
32 #include <vector>
33 
34 using namespace apache::thrift::transport;
35 
36 namespace {
37 constexpr char const* kCalciteUserName = "calcite";
38 constexpr char const* kCalciteUserPassword = "HyperInteractive";
39 } // namespace
40 
41 class CalciteServerClient;
42 
43 namespace Catalog_Namespace {
44 class SessionInfo;
45 } // namespace Catalog_Namespace
46 
47 namespace query_state {
48 class QueryStateProxy;
49 }
50 
51 struct SystemParameters;
52 
54 
55 // Forward declares for Thrift-generated classes
56 class TFilterPushDownInfo;
57 class TPlanResult;
58 class TCompletionHint;
59 
60 class Calcite final {
61  public:
62  Calcite(const int db_port,
63  const int port,
64  const std::string& data_dir,
65  const size_t calcite_max_mem,
66  const size_t service_timeout,
67  const bool service_keepalive,
68  const std::string& udf_filename = "");
69  Calcite(const SystemParameters& db_parameters,
70  const std::string& data_dir,
71  const std::string& udf_filename = "");
72  // sql_string may differ from what is in query_state due to legacy_syntax option.
73  TPlanResult process(query_state::QueryStateProxy,
74  std::string sql_string,
75  const std::vector<TFilterPushDownInfo>& filter_push_down_info,
76  const bool legacy_syntax,
77  const bool is_explain,
78  const bool is_view_optimize,
79  const bool check_privileges,
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  void updateMetadata(std::string catalog, std::string table);
91  void close_calcite_server(bool log = true);
92  ~Calcite();
93  std::string getRuntimeExtensionFunctionWhitelist();
94  void setRuntimeExtensionFunctions(const std::vector<TUserDefinedFunction>& udfs,
95  const std::vector<TUserDefinedTableFunction>& udtfs,
96  bool isruntime = true);
97  std::string const getInternalSessionProxyUserName() { return kCalciteUserName; }
98  std::string const getInternalSessionProxyPassword() { return kCalciteUserPassword; }
99 
100  private:
101  void init(const int db_port,
102  const int port,
103  const std::string& data_dir,
104  const size_t calcite_max_mem,
105  const std::string& udf_filename);
106  void runServer(const int db_port,
107  const int port,
108  const std::string& data_dir,
109  const size_t calcite_max_mem,
110  const std::string& udf_filename);
111  TPlanResult processImpl(query_state::QueryStateProxy,
112  std::string sql_string,
113  const std::vector<TFilterPushDownInfo>& filter_push_down_info,
114  const bool legacy_syntax,
115  const bool is_explain,
116  const bool is_view_optimize,
117  const std::string& calcite_session_id);
118  std::vector<std::string> get_db_objects(const std::string ra);
119  void inner_close_calcite_server(bool log);
120  std::pair<std::shared_ptr<CalciteServerClient>, std::shared_ptr<TTransport>> getClient(
121  int port);
122 
123  int ping(int retry_num = 0, int max_retry = 50);
124 
125  std::shared_ptr<ThriftClientConnection> connMgr_;
128  bool service_keepalive_ = true;
129  int remote_calcite_port_ = -1;
130  std::string ssl_trust_store_;
131  std::string ssl_trust_password_;
132  std::string ssl_key_file_;
133  std::string ssl_keystore_;
135  std::string ssl_ca_file_;
136  std::string db_config_file_;
137  std::once_flag shutdown_once_flag_;
138 };
std::string db_config_file_
Definition: Calcite.h:136
std::once_flag shutdown_once_flag_
Definition: Calcite.h:137
std::string ssl_key_file_
Definition: Calcite.h:132
std::string ssl_keystore_
Definition: Calcite.h:133
std::string ssl_keystore_password_
Definition: Calcite.h:134
std::shared_ptr< ThriftClientConnection > connMgr_
Definition: Calcite.h:125
std::string ssl_trust_store_
Definition: Calcite.h:130
void init(LogOptions const &log_opts)
Definition: Logger.cpp:290
constexpr char const * kCalciteUserPassword
Definition: Calcite.h:38
std::string ssl_ca_file_
Definition: Calcite.h:135
std::string const getInternalSessionProxyPassword()
Definition: Calcite.h:98
size_t service_timeout_
Definition: Calcite.h:127
std::string const getInternalSessionProxyUserName()
Definition: Calcite.h:97
bool server_available_
Definition: Calcite.h:126
std::string ssl_trust_password_
Definition: Calcite.h:131
constexpr char const * kCalciteUserName
Definition: Calcite.h:37