OmniSciDB  29e35f4d58
Calcite.cpp
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.cpp
19  * Author: michael
20  *
21  * Created on November 23, 2015, 9:33 AM
22  */
23 
24 #include "Calcite.h"
25 #include "Catalog/Catalog.h"
26 #include "Shared/ConfigResolve.h"
27 #include "Shared/Logger.h"
28 #include "Shared/MapDParameters.h"
29 #include "Shared/ThriftClient.h"
30 #include "Shared/fixautotools.h"
31 #include "Shared/mapd_shared_ptr.h"
32 #include "Shared/mapdpath.h"
33 #include "Shared/measure.h"
35 
36 #include <thrift/protocol/TBinaryProtocol.h>
37 #include <thrift/transport/TSocket.h>
38 #include <thrift/transport/TTransportUtils.h>
39 #include <type_traits>
40 
41 #include "gen-cpp/CalciteServer.h"
42 
43 #include "rapidjson/document.h"
44 
45 #include <utility>
46 
47 using namespace rapidjson;
48 using namespace apache::thrift;
49 using namespace apache::thrift::protocol;
50 using namespace apache::thrift::transport;
51 
52 namespace {
53 template <typename XDEBUG_OPTION,
54  typename REMOTE_DEBUG_OPTION,
55  typename... REMAINING_ARGS>
56 int wrapped_execlp(char const* path,
57  XDEBUG_OPTION&& x_debug,
58  REMOTE_DEBUG_OPTION&& remote_debug,
59  REMAINING_ARGS&&... standard_args) {
60  if (std::is_same<JVMRemoteDebugSelector, PreprocessorTrue>::value) {
61  return execlp(
62  path, x_debug, remote_debug, std::forward<REMAINING_ARGS>(standard_args)...);
63  }
64  return execlp(path, std::forward<REMAINING_ARGS>(standard_args)...);
65 }
66 } // namespace
67 
68 static void start_calcite_server_as_daemon(const int mapd_port,
69  const int port,
70  const std::string& data_dir,
71  const size_t calcite_max_mem,
72  const std::string& ssl_trust_store,
73  const std::string& ssl_trust_password_X,
74  const std::string& ssl_keystore,
75  const std::string& ssl_keystore_password_X,
76  const std::string& ssl_key_file,
77  const std::string& mapd_config_file,
78  const std::string& udf_filename) {
79  std::string const xDebug = "-Xdebug";
80  std::string const remoteDebug =
81  "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005";
82  std::string xmxP = "-Xmx" + std::to_string(calcite_max_mem) + "m";
83  std::string jarP = "-jar";
84  std::string jarD =
85  mapd_root_abs_path() + "/bin/calcite-1.0-SNAPSHOT-jar-with-dependencies.jar";
86  std::string extensionsP = "-e";
87  std::string extensionsD = mapd_root_abs_path() + "/QueryEngine/";
88  std::string dataP = "-d";
89  std::string dataD = data_dir;
90  std::string localPortP = "-p";
91  std::string localPortD = std::to_string(port);
92  std::string mapdPortP = "-m";
93  std::string mapdPortD = std::to_string(mapd_port);
94  std::string mapdTrustStoreP = "-T";
95  std::string mapdTrustPasswdP = "-P";
96  std::string mapdConfigFileP = "-c";
97  std::string mapdKeyStoreP = "-Y";
98  std::string mapdKeyStorePasswdP = "-Z";
99  std::string mapdLogDirectory = "-DMAPD_LOG_DIR=" + data_dir;
100  std::string userDefinedFunctionsP = "";
101  std::string userDefinedFunctionsD = "";
102 
103  if (!udf_filename.empty()) {
104  userDefinedFunctionsP += "-u";
105  userDefinedFunctionsD += udf_filename;
106  }
107 
108  // If a config file hasn't been supplied then put the password in the params
109  // otherwise send an empty string and Calcite should get it from the config file.
110  std::string key_store_password =
111  (mapd_config_file == "") ? ssl_keystore_password_X : "";
112  std::string trust_store_password = (mapd_config_file == "") ? ssl_trust_password_X : "";
113 
114  int pid = fork();
115  if (pid == 0) {
116  int i;
117 
118  if (udf_filename.empty()) {
119  i = wrapped_execlp("java",
120  xDebug.c_str(),
121  remoteDebug.c_str(),
122  xmxP.c_str(),
123  mapdLogDirectory.c_str(),
124  jarP.c_str(),
125  jarD.c_str(),
126  extensionsP.c_str(),
127  extensionsD.c_str(),
128  dataP.c_str(),
129  dataD.c_str(),
130  localPortP.c_str(),
131  localPortD.c_str(),
132  mapdPortP.c_str(),
133  mapdPortD.c_str(),
134  mapdTrustStoreP.c_str(),
135  ssl_trust_store.c_str(),
136  mapdTrustPasswdP.c_str(),
137  trust_store_password.c_str(),
138  mapdKeyStoreP.c_str(),
139  ssl_keystore.c_str(),
140  mapdKeyStorePasswdP.c_str(),
141  key_store_password.c_str(),
142  mapdConfigFileP.c_str(),
143  mapd_config_file.c_str(),
144  (char*)0);
145  } else {
146  i = wrapped_execlp("java",
147  xDebug.c_str(),
148  remoteDebug.c_str(),
149  xmxP.c_str(),
150  mapdLogDirectory.c_str(),
151  jarP.c_str(),
152  jarD.c_str(),
153  extensionsP.c_str(),
154  extensionsD.c_str(),
155  dataP.c_str(),
156  dataD.c_str(),
157  localPortP.c_str(),
158  localPortD.c_str(),
159  mapdPortP.c_str(),
160  mapdPortD.c_str(),
161  mapdTrustStoreP.c_str(),
162  ssl_trust_store.c_str(),
163  mapdTrustPasswdP.c_str(),
164  trust_store_password.c_str(),
165  mapdKeyStoreP.c_str(),
166  ssl_keystore.c_str(),
167  mapdKeyStorePasswdP.c_str(),
168  key_store_password.c_str(),
169  mapdConfigFileP.c_str(),
170  mapd_config_file.c_str(),
171  userDefinedFunctionsP.c_str(),
172  userDefinedFunctionsD.c_str(),
173  (char*)0);
174  }
175 
176  if (i) {
177  int errsv = errno;
178  LOG(FATAL) << "Failed to start Calcite server [errno=" << errsv
179  << "]: " << strerror(errsv);
180  } else {
181  LOG(INFO) << "Successfully started Calcite server";
182  }
183  }
184 }
185 
186 std::pair<mapd::shared_ptr<CalciteServerClient>, mapd::shared_ptr<TTransport>>
188  const auto transport = connMgr_->open_buffered_client_transport(
189  "localhost", port, ssl_ca_file_, true, 2000, 5000, 5000);
190  try {
191  transport->open();
192 
193  } catch (TException& tx) {
194  throw tx;
195  } catch (std::exception& ex) {
196  throw ex;
197  }
198  mapd::shared_ptr<TProtocol> protocol(new TBinaryProtocol(transport));
199  mapd::shared_ptr<CalciteServerClient> client;
200  client.reset(new CalciteServerClient(protocol));
201  std::pair<mapd::shared_ptr<CalciteServerClient>, mapd::shared_ptr<TTransport>> ret;
202  return std::make_pair(client, transport);
203 }
204 
205 void Calcite::runServer(const int mapd_port,
206  const int port,
207  const std::string& data_dir,
208  const size_t calcite_max_mem,
209  const std::string& udf_filename) {
210  LOG(INFO) << "Running Calcite server as a daemon";
211 
212  // ping server to see if for any reason there is an orphaned one
213  int ping_time = ping();
214  if (ping_time > -1) {
215  // we have an orphaned server shut it down
216  LOG(ERROR)
217  << "Appears to be orphaned Calcite server already running, shutting it down";
218  LOG(ERROR) << "Please check that you are not trying to run two servers on same port";
219  LOG(ERROR) << "Attempting to shutdown orphaned Calcite server";
220  try {
221  auto clientP = getClient(remote_calcite_port_);
222  clientP.first->shutdown();
223  clientP.second->close();
224  LOG(ERROR) << "orphaned Calcite server shutdown";
225 
226  } catch (TException& tx) {
227  LOG(ERROR) << "Failed to shutdown orphaned Calcite server, reason: " << tx.what();
228  }
229  }
230 
231  // start the calcite server as a seperate process
233  port,
234  data_dir,
235  calcite_max_mem,
236  ssl_trust_store_,
237  ssl_trust_password_,
238  ssl_keystore_,
239  ssl_keystore_password_,
240  ssl_key_file_,
241  mapd_config_file_,
242  udf_filename);
243 
244  // check for new server for 5 seconds max
245  std::this_thread::sleep_for(std::chrono::milliseconds(200));
246  int retry_max = 50;
247  for (int i = 2; i <= retry_max; i++) {
248  int ping_time = ping(i, retry_max);
249  if (ping_time > -1) {
250  LOG(INFO) << "Calcite server start took " << i * 100 << " ms ";
251  LOG(INFO) << "ping took " << ping_time << " ms ";
252  server_available_ = true;
253  return;
254  } else {
255  // wait 100 ms
256  std::this_thread::sleep_for(std::chrono::milliseconds(100));
257  }
258  }
259  server_available_ = false;
260  LOG(FATAL) << "Could not connect to Calcite remote server running on port [" << port
261  << "]";
262 }
263 
264 // ping existing server
265 // return -1 if no ping response
266 // params set to default values in header
267 int Calcite::ping(int retry_num, int max_retry) {
268  try {
269  auto ms = measure<>::execution([&]() {
270  auto clientP = getClient(remote_calcite_port_);
271  clientP.first->ping();
272  clientP.second->close();
273  });
274  return ms;
275 
276  } catch (TException& tx) {
277  if (retry_num >= max_retry) {
278  LOG(ERROR) << "Problems connecting to Calcite. Thrift error - " << tx.what();
279  }
280  return -1;
281  }
282 }
283 
284 Calcite::Calcite(const int mapd_port,
285  const int calcite_port,
286  const std::string& data_dir,
287  const size_t calcite_max_mem,
288  const std::string& udf_filename)
289  : server_available_(false) {
290  init(mapd_port, calcite_port, data_dir, calcite_max_mem, udf_filename);
291 }
292 
293 void Calcite::init(const int mapd_port,
294  const int calcite_port,
295  const std::string& data_dir,
296  const size_t calcite_max_mem,
297  const std::string& udf_filename) {
298  LOG(INFO) << "Creating Calcite Handler, Calcite Port is " << calcite_port
299  << " base data dir is " << data_dir;
300  connMgr_ = std::make_shared<ThriftClientConnection>();
301  if (calcite_port < 0) {
302  CHECK(false) << "JNI mode no longer supported.";
303  }
304  if (calcite_port == 0) {
305  // dummy process for initdb
306  remote_calcite_port_ = calcite_port;
307  server_available_ = false;
308  } else {
309  remote_calcite_port_ = calcite_port;
310  runServer(mapd_port, calcite_port, data_dir, calcite_max_mem, udf_filename);
311  server_available_ = true;
312  }
313 }
314 
315 Calcite::Calcite(const MapDParameters& mapd_parameter,
316  const std::string& data_dir,
317  const std::string& udf_filename)
318  : ssl_trust_store_(mapd_parameter.ssl_trust_store)
319  , ssl_trust_password_(mapd_parameter.ssl_trust_password)
320  , ssl_key_file_(mapd_parameter.ssl_key_file)
321  , ssl_keystore_(mapd_parameter.ssl_keystore)
322  , ssl_keystore_password_(mapd_parameter.ssl_keystore_password)
323  , ssl_ca_file_(mapd_parameter.ssl_trust_ca_file)
324  , mapd_config_file_(mapd_parameter.config_file) {
325  init(mapd_parameter.omnisci_server_port,
326  mapd_parameter.calcite_port,
327  data_dir,
328  mapd_parameter.calcite_max_mem,
329  udf_filename);
330 }
331 
332 void Calcite::updateMetadata(std::string catalog, std::string table) {
333  if (server_available_) {
334  auto ms = measure<>::execution([&]() {
335  auto clientP = getClient(remote_calcite_port_);
336  clientP.first->updateMetadata(catalog, table);
337  clientP.second->close();
338  });
339  LOG(INFO) << "Time to updateMetadata " << ms << " (ms)";
340  } else {
341  LOG(INFO) << "Not routing to Calcite, server is not up";
342  }
343 }
344 
346  std::vector<std::string> tableOrViewNames,
347  AccessPrivileges tablePrivs,
348  AccessPrivileges viewPrivs) {
349  Catalog_Namespace::Catalog& catalog = session_info.getCatalog();
350 
351  for (auto tableOrViewName : tableOrViewNames) {
352  const TableDescriptor* tableMeta =
353  catalog.getMetadataForTable(tableOrViewName, false);
354 
355  if (!tableMeta) {
356  throw std::runtime_error("unknown table of view: " + tableOrViewName);
357  }
358 
359  DBObjectKey key;
360  key.dbId = catalog.getCurrentDB().dbId;
363  key.objectId = tableMeta->tableId;
364  AccessPrivileges privs = tableMeta->isView ? viewPrivs : tablePrivs;
365  DBObject dbobject(key, privs, tableMeta->userId);
366  std::vector<DBObject> privObjects{dbobject};
367 
368  if (!privs.hasAny()) {
369  throw std::runtime_error("Operation not supported for object " + tableOrViewName);
370  }
371 
372  if (!Catalog_Namespace::SysCatalog::instance().checkPrivileges(
373  session_info.get_currentUser(), privObjects)) {
374  throw std::runtime_error("Violation of access privileges: user " +
375  session_info.get_currentUser().userName +
376  " has no proper privileges for object " + tableOrViewName);
377  }
378  }
379 }
380 
381 TPlanResult Calcite::process(
382  query_state::QueryStateProxy query_state_proxy,
383  std::string sql_string,
384  const std::vector<TFilterPushDownInfo>& filter_push_down_info,
385  const bool legacy_syntax,
386  const bool is_explain,
387  const bool is_view_optimize,
388  const std::string& calcite_session_id) {
389  TPlanResult result = processImpl(query_state_proxy,
390  std::move(sql_string),
391  filter_push_down_info,
392  legacy_syntax,
393  is_explain,
394  is_view_optimize,
395  calcite_session_id);
396 
397  AccessPrivileges NOOP;
398 
399  if (!is_explain) {
400  // check the individual tables
401  auto const session_ptr = query_state_proxy.getQueryState().getConstSessionInfo();
402  checkPermissionForTables(*session_ptr,
403  result.primary_accessed_objects.tables_selected_from,
406  checkPermissionForTables(*session_ptr,
407  result.primary_accessed_objects.tables_inserted_into,
409  NOOP);
410  checkPermissionForTables(*session_ptr,
411  result.primary_accessed_objects.tables_updated_in,
413  NOOP);
414  checkPermissionForTables(*session_ptr,
415  result.primary_accessed_objects.tables_deleted_from,
417  NOOP);
418  }
419 
420  return result;
421 }
422 
423 std::vector<TCompletionHint> Calcite::getCompletionHints(
424  const Catalog_Namespace::SessionInfo& session_info,
425  const std::vector<std::string>& visible_tables,
426  const std::string sql_string,
427  const int cursor) {
428  std::vector<TCompletionHint> hints;
429  auto& cat = session_info.getCatalog();
430  const auto user = session_info.get_currentUser().userName;
431  const auto session = session_info.get_session_id();
432  const auto catalog = cat.getCurrentDB().dbName;
433  auto client = getClient(remote_calcite_port_);
434  client.first->getCompletionHints(
435  hints, user, session, catalog, visible_tables, sql_string, cursor);
436  return hints;
437 }
438 
439 std::vector<std::string> Calcite::get_db_objects(const std::string ra) {
440  std::vector<std::string> v_db_obj;
441  Document document;
442  document.Parse(ra.c_str());
443  const Value& rels = document["rels"];
444  CHECK(rels.IsArray());
445  for (auto& v : rels.GetArray()) {
446  std::string relOp(v["relOp"].GetString());
447  if (!relOp.compare("EnumerableTableScan")) {
448  std::string x;
449  auto t = v["table"].GetArray();
450  x = t[1].GetString();
451  v_db_obj.push_back(x);
452  }
453  }
454 
455  return v_db_obj;
456 }
457 
459  query_state::QueryStateProxy query_state_proxy,
460  const std::string sql_string,
461  const std::vector<TFilterPushDownInfo>& filter_push_down_info,
462  const bool legacy_syntax,
463  const bool is_explain,
464  const bool is_view_optimize,
465  const std::string& calcite_session_id) {
466  query_state::Timer timer = query_state_proxy.createTimer(__func__);
467  const auto& user_session_info = query_state_proxy.getQueryState().getConstSessionInfo();
468  const auto& cat = user_session_info->getCatalog();
469  const std::string user = getInternalSessionProxyUserName();
470  const std::string catalog = cat.getCurrentDB().dbName;
471  LOG(INFO) << "User " << user << " catalog " << catalog << " sql '" << sql_string << "'";
472  LOG(IR) << "SQL query\n" << sql_string << "\nEnd of SQL query";
473  LOG(PTX) << "SQL query\n" << sql_string << "\nEnd of SQL query";
474 
475  TPlanResult ret;
476  if (server_available_) {
477  try {
478  // calcite_session_id would be an empty string when accessed by internal resources
479  // that would not access `process` through handler instance, like for eg: Unit
480  // Tests. In these cases we would use the session_id from query state.
481  auto ms = measure<>::execution([&]() {
482  auto clientP = getClient(remote_calcite_port_);
483  clientP.first->process(ret,
484  user,
485  calcite_session_id.empty()
486  ? user_session_info->get_session_id()
487  : calcite_session_id,
488  catalog,
489  sql_string,
490  filter_push_down_info,
491  legacy_syntax,
492  is_explain,
493  is_view_optimize);
494  clientP.second->close();
495  });
496 
497  // LOG(INFO) << ret.plan_result;
498  LOG(INFO) << "Time in Thrift "
499  << (ms > ret.execution_time_ms ? ms - ret.execution_time_ms : 0)
500  << " (ms), Time in Java Calcite server " << ret.execution_time_ms
501  << " (ms)";
502  } catch (InvalidParseRequest& e) {
503  throw std::invalid_argument(e.whyUp);
504  } catch (const std::exception& ex) {
505  LOG(FATAL)
506  << "Error occurred trying to communicate with Calcite server, the error was: '"
507  << ex.what() << "', omnisci_server restart will be required";
508  return ret; // satisfy return-type warning
509  }
510  } else {
511  LOG(INFO) << "Not routing to Calcite, server is not up";
512  ret.plan_result = "";
513  }
514  return ret;
515 }
516 
518  if (server_available_) {
519  TPlanResult ret;
520  std::string whitelist;
521 
522  auto clientP = getClient(remote_calcite_port_);
523  clientP.first->getExtensionFunctionWhitelist(whitelist);
524  clientP.second->close();
525  VLOG(1) << whitelist;
526  return whitelist;
527  } else {
528  LOG(FATAL) << "Not routing to Calcite, server is not up";
529  return "";
530  }
531  CHECK(false);
532  return "";
533 }
534 
536  if (server_available_) {
537  TPlanResult ret;
538  std::string whitelist;
539 
540  auto clientP = getClient(remote_calcite_port_);
541  clientP.first->getUserDefinedFunctionWhitelist(whitelist);
542  clientP.second->close();
543  VLOG(1) << "User defined functions whitelist loaded from Calcite: " << whitelist;
544  return whitelist;
545  } else {
546  LOG(FATAL) << "Not routing to Calcite, server is not up";
547  return "";
548  }
549  UNREACHABLE();
550  return "";
551 }
552 
554  std::call_once(shutdown_once_flag_,
555  [this, log]() { this->inner_close_calcite_server(log); });
556 }
557 
559  if (server_available_) {
560  LOG_IF(INFO, log) << "Shutting down Calcite server";
561  try {
562  auto clientP = getClient(remote_calcite_port_);
563  clientP.first->shutdown();
564  clientP.second->close();
565  } catch (const std::exception& e) {
566  if (std::string(e.what()) != "connect() failed: Connection refused" &&
567  std::string(e.what()) != "socket open() error: Connection refused" &&
568  std::string(e.what()) != "No more data to read.") {
569  std::cerr << "Error shutting down Calcite server: " << e.what() << std::endl;
570  } // else Calcite already shut down
571  }
572  LOG_IF(INFO, log) << "shut down Calcite";
573  server_available_ = false;
574  }
575 }
576 
578  close_calcite_server(false);
579 }
580 
582  if (server_available_) {
583  TPlanResult ret;
584  std::string whitelist;
585  auto clientP = getClient(remote_calcite_port_);
586  clientP.first->getRuntimeExtensionFunctionWhitelist(whitelist);
587  clientP.second->close();
588  VLOG(1) << "Runtime extension functions whitelist loaded from Calcite: " << whitelist;
589  return whitelist;
590  } else {
591  LOG(FATAL) << "Not routing to Calcite, server is not up";
592  return "";
593  }
594  UNREACHABLE();
595  return "";
596 }
597 
599  const std::vector<TUserDefinedFunction>& udfs,
600  const std::vector<TUserDefinedTableFunction>& udtfs) {
601  if (server_available_) {
602  auto clientP = getClient(remote_calcite_port_);
603  clientP.first->setRuntimeExtensionFunctions(udfs, udtfs);
604  clientP.second->close();
605  } else {
606  LOG(FATAL) << "Not routing to Calcite, server is not up";
607  }
608 }
std::vector< std::string > get_db_objects(const std::string ra)
Definition: Calcite.cpp:439
std::once_flag shutdown_once_flag_
Definition: Calcite.h:131
class for a per-database catalog. also includes metadata for the current database and the current use...
Definition: Catalog.h:81
const TableDescriptor * getMetadataForTable(const std::string &tableName, const bool populateFragmenter=true) const
Returns a pointer to a const TableDescriptor struct matching the provided tableName.
std::string ssl_key_file_
Definition: Calcite.h:126
#define LOG(tag)
Definition: Logger.h:188
std::string ssl_keystore_
Definition: Calcite.h:127
mapd::shared_ptr< ThriftClientConnection > connMgr_
Definition: Calcite.h:121
std::string mapd_root_abs_path()
Definition: mapdpath.h:30
static const AccessPrivileges INSERT_INTO_TABLE
Definition: DBObject.h:154
std::string ssl_keystore_password_
Definition: Calcite.h:128
TPlanResult processImpl(query_state::QueryStateProxy, std::string sql_string, const std::vector< TFilterPushDownInfo > &filter_push_down_info, const bool legacy_syntax, const bool is_explain, const bool is_view_optimize, const std::string &calcite_session_id)
Definition: Calcite.cpp:458
#define UNREACHABLE()
Definition: Logger.h:237
TPlanResult process(query_state::QueryStateProxy, std::string sql_string, const std::vector< TFilterPushDownInfo > &filter_push_down_info, const bool legacy_syntax, const bool is_explain, const bool is_view_optimize, const std::string &calcite_session_id="")
Definition: Calcite.cpp:381
const UserMetadata & get_currentUser() const
Definition: SessionInfo.h:93
int32_t objectId
Definition: DBObject.h:56
Timer createTimer(char const *event_name)
Definition: QueryState.cpp:111
std::string get_session_id() const
Definition: SessionInfo.h:98
static const AccessPrivileges SELECT_FROM_TABLE
Definition: DBObject.h:153
std::string ssl_trust_store_
Definition: Calcite.h:124
std::string to_string(char const *&&v)
#define LOG_IF(severity, condition)
Definition: Logger.h:279
void updateMetadata(std::string catalog, std::string table)
Definition: Calcite.cpp:332
This file contains the class specification and related data structures for Catalog.
bool hasAny() const
Definition: DBObject.h:133
static SysCatalog & instance()
Definition: SysCatalog.h:257
int wrapped_execlp(char const *path, XDEBUG_OPTION &&x_debug, REMOTE_DEBUG_OPTION &&remote_debug, REMAINING_ARGS &&... standard_args)
Definition: Calcite.cpp:56
void setRuntimeExtensionFunctions(const std::vector< TUserDefinedFunction > &udfs, const std::vector< TUserDefinedTableFunction > &udtfs)
Definition: Calcite.cpp:598
std::vector< TCompletionHint > getCompletionHints(const Catalog_Namespace::SessionInfo &session_info, const std::vector< std::string > &visible_tables, const std::string sql_string, const int cursor)
Definition: Calcite.cpp:423
QueryState & getQueryState()
Definition: QueryState.h:172
Catalog & getCatalog() const
Definition: SessionInfo.h:90
std::string ssl_ca_file_
Definition: Calcite.h:129
static const AccessPrivileges DELETE_FROM_TABLE
Definition: DBObject.h:156
int ping(int retry_num=0, int max_retry=50)
Definition: Calcite.cpp:267
const DBMetadata & getCurrentDB() const
Definition: Catalog.h:176
std::string getUserDefinedFunctionWhitelist()
Definition: Calcite.cpp:535
size_t calcite_max_mem
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.cpp:284
static void start_calcite_server_as_daemon(const int mapd_port, const int port, const std::string &data_dir, const size_t calcite_max_mem, const std::string &ssl_trust_store, const std::string &ssl_trust_password_X, const std::string &ssl_keystore, const std::string &ssl_keystore_password_X, const std::string &ssl_key_file, const std::string &mapd_config_file, const std::string &udf_filename)
Definition: Calcite.cpp:68
std::shared_ptr< Catalog_Namespace::SessionInfo const > getConstSessionInfo() const
Definition: QueryState.cpp:75
static const AccessPrivileges SELECT_FROM_VIEW
Definition: DBObject.h:173
int remote_calcite_port_
Definition: Calcite.h:123
int32_t dbId
Definition: DBObject.h:55
std::string const getInternalSessionProxyUserName()
Definition: Calcite.h:93
void inner_close_calcite_server(bool log)
Definition: Calcite.cpp:558
std::string mapd_config_file_
Definition: Calcite.h:130
bool server_available_
Definition: Calcite.h:122
#define CHECK(condition)
Definition: Logger.h:193
static TimeT::rep execution(F func, Args &&... args)
Definition: sample.cpp:29
int32_t permissionType
Definition: DBObject.h:54
void runServer(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.cpp:205
specifies the content in-memory of a row in the table metadata table
void init(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.cpp:293
static const AccessPrivileges UPDATE_IN_TABLE
Definition: DBObject.h:155
std::string ssl_trust_password_
Definition: Calcite.h:125
~Calcite()
Definition: Calcite.cpp:577
std::string getExtensionFunctionWhitelist()
Definition: Calcite.cpp:517
std::pair< mapd::shared_ptr< CalciteServerClient >, mapd::shared_ptr< TTransport > > getClient(int port)
Definition: Calcite.cpp:187
void checkPermissionForTables(const Catalog_Namespace::SessionInfo &session_info, std::vector< std::string > tableOrViewNames, AccessPrivileges tablePrivs, AccessPrivileges viewPrivs)
Definition: Calcite.cpp:345
std::string getRuntimeExtensionFunctionWhitelist()
Definition: Calcite.cpp:581
#define VLOG(n)
Definition: Logger.h:283
void close_calcite_server(bool log=true)
Definition: Calcite.cpp:553