OmniSciDB  8a228a1076
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 "Shared/mapd_shared_ptr.h"
27 #include "gen-cpp/extension_functions_types.h"
28 
29 #include <thrift/transport/TTransport.h>
30 
31 #include <mutex>
32 #include <string>
33 #include <vector>
34 
35 using namespace apache::thrift::transport;
36 
37 namespace {
38 constexpr char const* kCalciteUserName = "calcite";
39 constexpr char const* kCalciteUserPassword = "HyperInteractive";
40 } // namespace
41 
42 class CalciteServerClient;
43 
44 namespace Catalog_Namespace {
45 class SessionInfo;
46 } // namespace Catalog_Namespace
47 
48 namespace query_state {
49 class QueryStateProxy;
50 }
51 
52 struct SystemParameters;
53 
55 
56 // Forward declares for Thrift-generated classes
57 class TFilterPushDownInfo;
58 class TPlanResult;
59 class TCompletionHint;
60 
61 class Calcite final {
62  public:
63  Calcite(const int db_port,
64  const int port,
65  const std::string& data_dir,
66  const size_t calcite_max_mem,
67  const size_t service_timeout,
68  const bool service_keepalive,
69  const std::string& udf_filename = "");
70  Calcite(const SystemParameters& db_parameters,
71  const std::string& data_dir,
72  const std::string& udf_filename = "");
73  // sql_string may differ from what is in query_state due to legacy_syntax option.
74  TPlanResult process(query_state::QueryStateProxy,
75  std::string sql_string,
76  const std::vector<TFilterPushDownInfo>& filter_push_down_info,
77  const bool legacy_syntax,
78  const bool is_explain,
79  const bool is_view_optimize,
80  const bool check_privileges,
81  const std::string& calcite_session_id = "");
82  void checkAccessedObjectsPrivileges(query_state::QueryStateProxy query_state_prox,
83  TPlanResult plan) const;
84  std::vector<TCompletionHint> getCompletionHints(
85  const Catalog_Namespace::SessionInfo& session_info,
86  const std::vector<std::string>& visible_tables,
87  const std::string sql_string,
88  const int cursor);
89  std::string getExtensionFunctionWhitelist();
90  std::string getUserDefinedFunctionWhitelist();
91  void updateMetadata(std::string catalog, std::string table);
92  void close_calcite_server(bool log = true);
93  ~Calcite();
94  std::string getRuntimeExtensionFunctionWhitelist();
95  void setRuntimeExtensionFunctions(const std::vector<TUserDefinedFunction>& udfs,
96  const std::vector<TUserDefinedTableFunction>& udtfs);
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<mapd::shared_ptr<CalciteServerClient>, mapd::shared_ptr<TTransport>>
121  getClient(int port);
122 
123  int ping(int retry_num = 0, int max_retry = 50);
124 
125  mapd::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
mapd::shared_ptr< ThriftClientConnection > connMgr_
Definition: Calcite.h:125
std::string ssl_keystore_password_
Definition: Calcite.h:134
std::string ssl_trust_store_
Definition: Calcite.h:130
void init(LogOptions const &log_opts)
Definition: Logger.cpp:280
constexpr char const * kCalciteUserPassword
Definition: Calcite.h:39
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:38