OmniSciDB  1dac507f6e
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Calcite.h
Go to the documentation of this file.
1 /*
2  * Copyright 2017 MapD Technologies, 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 #ifndef CALCITE_H
25 #define CALCITE_H
26 
27 #include "Shared/mapd_shared_ptr.h"
28 #include "gen-cpp/extension_functions_types.h"
29 
30 #include <thrift/transport/TTransport.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 MapDParameters;
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 mapd_port,
65  const int port,
66  const std::string& data_dir,
67  const size_t calcite_max_mem,
68  const std::string& udf_filename = "");
69  Calcite(const MapDParameters& mapd_parameter,
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 std::string& calcite_session_id = "");
80  std::vector<TCompletionHint> getCompletionHints(
81  const Catalog_Namespace::SessionInfo& session_info,
82  const std::vector<std::string>& visible_tables,
83  const std::string sql_string,
84  const int cursor);
85  std::string getExtensionFunctionWhitelist();
86  std::string getUserDefinedFunctionWhitelist();
87  void updateMetadata(std::string catalog, std::string table);
88  void close_calcite_server(bool log = true);
89  ~Calcite();
90  std::string getRuntimeExtensionFunctionWhitelist();
91  void setRuntimeExtensionFunctions(const std::vector<TUserDefinedFunction>& udfs,
92  const std::vector<TUserDefinedTableFunction>& udtfs);
93  std::string const getInternalSessionProxyUserName() { return kCalciteUserName; }
94  std::string const getInternalSessionProxyPassword() { return kCalciteUserPassword; }
95 
96  private:
97  void init(const int mapd_port,
98  const int port,
99  const std::string& data_dir,
100  const size_t calcite_max_mem,
101  const std::string& udf_filename);
102  void runServer(const int mapd_port,
103  const int port,
104  const std::string& data_dir,
105  const size_t calcite_max_mem,
106  const std::string& udf_filename);
107  TPlanResult processImpl(query_state::QueryStateProxy,
108  std::string sql_string,
109  const std::vector<TFilterPushDownInfo>& filter_push_down_info,
110  const bool legacy_syntax,
111  const bool is_explain,
112  const bool is_view_optimize,
113  const std::string& calcite_session_id);
114  std::vector<std::string> get_db_objects(const std::string ra);
115  void inner_close_calcite_server(bool log);
116  std::pair<mapd::shared_ptr<CalciteServerClient>, mapd::shared_ptr<TTransport>>
117  getClient(int port);
118 
119  int ping();
120 
121  mapd::shared_ptr<ThriftClientConnection> connMgr_;
123  int remote_calcite_port_ = -1;
124  std::string ssl_trust_store_;
125  std::string ssl_trust_password_;
126  std::string ssl_key_file_;
127  std::string ssl_keystore_;
129  std::string ssl_cert_file_;
130  std::once_flag shutdown_once_flag_;
131 };
132 
133 #endif /* CALCITE_H */
std::once_flag shutdown_once_flag_
Definition: Calcite.h:130
std::string ssl_key_file_
Definition: Calcite.h:126
std::string ssl_keystore_
Definition: Calcite.h:127
mapd::shared_ptr< ThriftClientConnection > connMgr_
Definition: Calcite.h:121
std::string ssl_keystore_password_
Definition: Calcite.h:128
std::string ssl_trust_store_
Definition: Calcite.h:124
void init(LogOptions const &log_opts)
Definition: Logger.cpp:265
constexpr char const * kCalciteUserPassword
Definition: Calcite.h:40
std::string const getInternalSessionProxyPassword()
Definition: Calcite.h:94
std::string const getInternalSessionProxyUserName()
Definition: Calcite.h:93
std::string ssl_cert_file_
Definition: Calcite.h:129
bool server_available_
Definition: Calcite.h:122
std::string ssl_trust_password_
Definition: Calcite.h:125
constexpr char const * kCalciteUserName
Definition: Calcite.h:39