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