OmniSciDB  17c254d2f8
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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 "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 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  std::string const getInternalSessionProxyUserName() { return kCalciteUserName; }
97  std::string const getInternalSessionProxyPassword() { return kCalciteUserPassword; }
98 
99  private:
100  void init(const int db_port,
101  const int port,
102  const std::string& data_dir,
103  const size_t calcite_max_mem,
104  const std::string& udf_filename);
105  void runServer(const int db_port,
106  const int port,
107  const std::string& data_dir,
108  const size_t calcite_max_mem,
109  const std::string& udf_filename);
110  TPlanResult processImpl(query_state::QueryStateProxy,
111  std::string sql_string,
112  const std::vector<TFilterPushDownInfo>& filter_push_down_info,
113  const bool legacy_syntax,
114  const bool is_explain,
115  const bool is_view_optimize,
116  const std::string& calcite_session_id);
117  std::vector<std::string> get_db_objects(const std::string ra);
118  void inner_close_calcite_server(bool log);
119  std::pair<mapd::shared_ptr<CalciteServerClient>, mapd::shared_ptr<TTransport>>
120  getClient(int port);
121 
122  int ping(int retry_num = 0, int max_retry = 50);
123 
124  mapd::shared_ptr<ThriftClientConnection> connMgr_;
127  int remote_calcite_port_ = -1;
128  std::string ssl_trust_store_;
129  std::string ssl_trust_password_;
130  std::string ssl_key_file_;
131  std::string ssl_keystore_;
133  std::string ssl_ca_file_;
134  std::string db_config_file_;
135  std::once_flag shutdown_once_flag_;
136 };
std::string db_config_file_
Definition: Calcite.h:134
std::once_flag shutdown_once_flag_
Definition: Calcite.h:135
std::string ssl_key_file_
Definition: Calcite.h:130
std::string ssl_keystore_
Definition: Calcite.h:131
mapd::shared_ptr< ThriftClientConnection > connMgr_
Definition: Calcite.h:124
std::string ssl_keystore_password_
Definition: Calcite.h:132
std::string ssl_trust_store_
Definition: Calcite.h:128
void init(LogOptions const &log_opts)
Definition: Logger.cpp:276
constexpr char const * kCalciteUserPassword
Definition: Calcite.h:39
std::string ssl_ca_file_
Definition: Calcite.h:133
std::string const getInternalSessionProxyPassword()
Definition: Calcite.h:97
size_t service_timeout_
Definition: Calcite.h:126
std::string const getInternalSessionProxyUserName()
Definition: Calcite.h:96
bool server_available_
Definition: Calcite.h:125
std::string ssl_trust_password_
Definition: Calcite.h:129
constexpr char const * kCalciteUserName
Definition: Calcite.h:38