OmniSciDB  04ee39c94c
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 <mutex>
28 #include <string>
29 #include <thread>
30 #include <vector>
31 #include "Shared/MapDParameters.h"
32 #include "Shared/ThriftClient.h"
33 #include "Shared/mapd_shared_ptr.h"
34 #include "rapidjson/document.h"
35 
36 #include <thrift/transport/TTransport.h>
37 
38 using namespace apache::thrift::transport;
39 
40 class CalciteServerClient;
41 
42 namespace Catalog_Namespace {
43 class SessionInfo;
44 }
45 
46 // Forward declares for Thrift-generated classes
47 class TFilterPushDownInfo;
48 class TPlanResult;
49 class TCompletionHint;
50 
51 class Calcite {
52  public:
53  Calcite(const int mapd_port,
54  const int port,
55  const std::string& data_dir,
56  const size_t calcite_max_mem,
57  const std::string& udf_filename = "")
58  : Calcite(mapd_port, port, data_dir, calcite_max_mem, "", udf_filename){};
59  Calcite(const int mapd_port,
60  const int port,
61  const std::string& data_dir,
62  const size_t calcite_max_mem,
63  const std::string& session_prefix,
64  const std::string& udf_filename = "");
65  Calcite(const MapDParameters& mapd_parameter,
66  const std::string& data_dir,
67  const std::string& session_prefix,
68  const std::string& udf_filename = "");
69  TPlanResult process(const Catalog_Namespace::SessionInfo& session_info,
70  const std::string sql_string,
71  const std::vector<TFilterPushDownInfo>& filter_push_down_info,
72  const bool legacy_syntax,
73  const bool is_explain,
74  const bool is_view_optimize);
75  std::vector<TCompletionHint> getCompletionHints(
76  const Catalog_Namespace::SessionInfo& session_info,
77  const std::vector<std::string>& visible_tables,
78  const std::string sql_string,
79  const int cursor);
80  std::string getExtensionFunctionWhitelist();
81  std::string getUserDefinedFunctionWhitelist();
82  void updateMetadata(std::string catalog, std::string table);
83  void close_calcite_server(bool log = true);
84  virtual ~Calcite();
85  std::string getRuntimeUserDefinedFunctionWhitelist();
86  void setRuntimeUserDefinedFunction(std::string udf_string);
87  std::string& get_session_prefix() { return session_prefix_; }
88 
89  private:
90  void init(const int mapd_port,
91  const int port,
92  const std::string& data_dir,
93  const size_t calcite_max_mem,
94  const std::string& udf_filename);
95  void runServer(const int mapd_port,
96  const int port,
97  const std::string& data_dir,
98  const size_t calcite_max_mem,
99  const std::string& udf_filename);
100  TPlanResult processImpl(const Catalog_Namespace::SessionInfo& session_info,
101  const std::string sql_string,
102  const std::vector<TFilterPushDownInfo>& filter_push_down_info,
103  const bool legacy_syntax,
104  const bool is_explain,
105  const bool is_view_optimize);
106  std::vector<std::string> get_db_objects(const std::string ra);
107  void inner_close_calcite_server(bool log);
108  std::pair<mapd::shared_ptr<CalciteServerClient>, mapd::shared_ptr<TTransport>>
109  getClient(int port);
110 
112  int ping();
113 
114  mapd::shared_ptr<ThriftClientConnection> connMgr_;
116  int remote_calcite_port_ = -1;
117  std::string ssl_trust_store_;
118  std::string ssl_trust_password_;
119  std::string ssl_key_file_;
120  std::string ssl_keystore_;
122  std::string ssl_cert_file_;
123  std::string session_prefix_;
124  std::once_flag shutdown_once_flag_;
125 };
126 
127 #endif /* CALCITE_H */
std::once_flag shutdown_once_flag_
Definition: Calcite.h:124
std::string ssl_key_file_
Definition: Calcite.h:119
std::string ssl_keystore_
Definition: Calcite.h:120
mapd::shared_ptr< ThriftClientConnection > connMgr_
Definition: Calcite.h:114
std::string ssl_keystore_password_
Definition: Calcite.h:121
std::string ssl_trust_store_
Definition: Calcite.h:117
std::string & get_session_prefix()
Definition: Calcite.h:87
void init(LogOptions const &log_opts)
Definition: Logger.cpp:260
std::string session_prefix_
Definition: Calcite.h:123
Calcite(const int mapd_port, const int port, const std::string &data_dir, const size_t calcite_max_mem, const std::string &udf_filename="")
Definition: Calcite.h:53
std::thread calcite_server_thread_
Definition: Calcite.h:111
std::string ssl_cert_file_
Definition: Calcite.h:122
bool server_available_
Definition: Calcite.h:115
std::string ssl_trust_password_
Definition: Calcite.h:118