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