OmniSciDB  17c254d2f8
 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 "Shared/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(
188  "localhost", port, ssl_ca_file_, true, 2000, service_timeout_, service_timeout_);
189  try {
190  transport->open();
191 
192  } catch (TException& tx) {
193  throw tx;
194  } catch (std::exception& ex) {
195  throw ex;
196  }
197  mapd::shared_ptr<TProtocol> protocol(new TBinaryProtocol(transport));
198  mapd::shared_ptr<CalciteServerClient> client;
199  client.reset(new CalciteServerClient(protocol));
200  std::pair<mapd::shared_ptr<CalciteServerClient>, mapd::shared_ptr<TTransport>> ret;
201  return std::make_pair(client, transport);
202 }
203 
204 void Calcite::runServer(const int db_port,
205  const int port,
206  const std::string& data_dir,
207  const size_t calcite_max_mem,
208  const std::string& udf_filename) {
209  LOG(INFO) << "Running Calcite server as a daemon";
210 
211  // ping server to see if for any reason there is an orphaned one
212  int ping_time = ping();
213  if (ping_time > -1) {
214  // we have an orphaned server shut it down
215  LOG(ERROR)
216  << "Appears to be orphaned Calcite server already running, shutting it down";
217  LOG(ERROR) << "Please check that you are not trying to run two servers on same port";
218  LOG(ERROR) << "Attempting to shutdown orphaned Calcite server";
219  try {
220  auto clientP = getClient(remote_calcite_port_);
221  clientP.first->shutdown();
222  clientP.second->close();
223  LOG(ERROR) << "orphaned Calcite server shutdown";
224 
225  } catch (TException& tx) {
226  LOG(ERROR) << "Failed to shutdown orphaned Calcite server, reason: " << tx.what();
227  }
228  }
229 
230  // start the calcite server as a seperate process
232  port,
233  data_dir,
234  calcite_max_mem,
235  ssl_trust_store_,
236  ssl_trust_password_,
237  ssl_keystore_,
238  ssl_keystore_password_,
239  ssl_key_file_,
240  db_config_file_,
241  udf_filename);
242 
243  // check for new server for 30 seconds max
244  std::this_thread::sleep_for(std::chrono::milliseconds(200));
245  int retry_max = 300;
246  for (int i = 2; i <= retry_max; i++) {
247  int ping_time = ping(i, retry_max);
248  if (ping_time > -1) {
249  LOG(INFO) << "Calcite server start took " << i * 100 << " ms ";
250  LOG(INFO) << "ping took " << ping_time << " ms ";
251  server_available_ = true;
252  return;
253  } else {
254  // wait 100 ms
255  std::this_thread::sleep_for(std::chrono::milliseconds(100));
256  }
257  }
258  server_available_ = false;
259  LOG(FATAL) << "Could not connect to Calcite remote server running on port [" << port
260  << "]";
261 }
262 
263 // ping existing server
264 // return -1 if no ping response
265 // params set to default values in header
266 int Calcite::ping(int retry_num, int max_retry) {
267  try {
268  auto ms = measure<>::execution([&]() {
269  auto clientP = getClient(remote_calcite_port_);
270  clientP.first->ping();
271  clientP.second->close();
272  });
273  return ms;
274 
275  } catch (TException& tx) {
276  if (retry_num >= max_retry) {
277  LOG(ERROR) << "Problems connecting to Calcite. Thrift error - " << tx.what();
278  }
279  return -1;
280  }
281 }
282 
283 Calcite::Calcite(const int db_port,
284  const int calcite_port,
285  const std::string& data_dir,
286  const size_t calcite_max_mem,
287  const size_t service_timeout,
288  const std::string& udf_filename)
289  : server_available_(false), service_timeout_(service_timeout) {
290  init(db_port, calcite_port, data_dir, calcite_max_mem, udf_filename);
291 }
292 
293 void Calcite::init(const int db_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(db_port, calcite_port, data_dir, calcite_max_mem, udf_filename);
311  server_available_ = true;
312  }
313 }
314 
315 Calcite::Calcite(const SystemParameters& system_parameters,
316  const std::string& data_dir,
317  const std::string& udf_filename)
318  : service_timeout_(system_parameters.calcite_timeout)
319  , ssl_trust_store_(system_parameters.ssl_trust_store)
320  , ssl_trust_password_(system_parameters.ssl_trust_password)
321  , ssl_key_file_(system_parameters.ssl_key_file)
322  , ssl_keystore_(system_parameters.ssl_keystore)
323  , ssl_keystore_password_(system_parameters.ssl_keystore_password)
324  , ssl_ca_file_(system_parameters.ssl_trust_ca_file)
325  , db_config_file_(system_parameters.config_file) {
326  init(system_parameters.omnisci_server_port,
327  system_parameters.calcite_port,
328  data_dir,
329  system_parameters.calcite_max_mem,
330  udf_filename);
331 }
332 
333 void Calcite::updateMetadata(std::string catalog, std::string table) {
334  if (server_available_) {
335  auto ms = measure<>::execution([&]() {
336  auto clientP = getClient(remote_calcite_port_);
337  clientP.first->updateMetadata(catalog, table);
338  clientP.second->close();
339  });
340  LOG(INFO) << "Time to updateMetadata " << ms << " (ms)";
341  } else {
342  LOG(INFO) << "Not routing to Calcite, server is not up";
343  }
344 }
345 
347  std::vector<std::string> tableOrViewNames,
348  AccessPrivileges tablePrivs,
349  AccessPrivileges viewPrivs) {
350  Catalog_Namespace::Catalog& catalog = session_info.getCatalog();
351 
352  for (auto tableOrViewName : tableOrViewNames) {
353  const TableDescriptor* tableMeta =
354  catalog.getMetadataForTable(tableOrViewName, false);
355 
356  if (!tableMeta) {
357  throw std::runtime_error("unknown table of view: " + tableOrViewName);
358  }
359 
360  DBObjectKey key;
361  key.dbId = catalog.getCurrentDB().dbId;
364  key.objectId = tableMeta->tableId;
365  AccessPrivileges privs = tableMeta->isView ? viewPrivs : tablePrivs;
366  DBObject dbobject(key, privs, tableMeta->userId);
367  std::vector<DBObject> privObjects{dbobject};
368 
369  if (!privs.hasAny()) {
370  throw std::runtime_error("Operation not supported for object " + tableOrViewName);
371  }
372 
373  if (!Catalog_Namespace::SysCatalog::instance().checkPrivileges(
374  session_info.get_currentUser(), privObjects)) {
375  throw std::runtime_error("Violation of access privileges: user " +
376  session_info.get_currentUser().userName +
377  " has no proper privileges for object " + tableOrViewName);
378  }
379  }
380 }
381 
382 TPlanResult Calcite::process(
383  query_state::QueryStateProxy query_state_proxy,
384  std::string sql_string,
385  const std::vector<TFilterPushDownInfo>& filter_push_down_info,
386  const bool legacy_syntax,
387  const bool is_explain,
388  const bool is_view_optimize,
389  const bool check_privileges,
390  const std::string& calcite_session_id) {
391  TPlanResult result = processImpl(query_state_proxy,
392  std::move(sql_string),
393  filter_push_down_info,
394  legacy_syntax,
395  is_explain,
396  is_view_optimize,
397  calcite_session_id);
398  if (check_privileges && !is_explain) {
399  checkAccessedObjectsPrivileges(query_state_proxy, result);
400  }
401  return result;
402 }
403 
405  query_state::QueryStateProxy query_state_proxy,
406  TPlanResult plan) const {
407  AccessPrivileges NOOP;
408  // check the individual tables
409  auto const session_ptr = query_state_proxy.getQueryState().getConstSessionInfo();
410  checkPermissionForTables(*session_ptr,
411  plan.primary_accessed_objects.tables_selected_from,
414  checkPermissionForTables(*session_ptr,
415  plan.primary_accessed_objects.tables_inserted_into,
417  NOOP);
418  checkPermissionForTables(*session_ptr,
419  plan.primary_accessed_objects.tables_updated_in,
421  NOOP);
422  checkPermissionForTables(*session_ptr,
423  plan.primary_accessed_objects.tables_deleted_from,
425  NOOP);
426 }
427 
428 std::vector<TCompletionHint> Calcite::getCompletionHints(
429  const Catalog_Namespace::SessionInfo& session_info,
430  const std::vector<std::string>& visible_tables,
431  const std::string sql_string,
432  const int cursor) {
433  std::vector<TCompletionHint> hints;
434  auto& cat = session_info.getCatalog();
435  const auto user = session_info.get_currentUser().userName;
436  const auto session = session_info.get_session_id();
437  const auto catalog = cat.getCurrentDB().dbName;
438  auto client = getClient(remote_calcite_port_);
439  client.first->getCompletionHints(
440  hints, user, session, catalog, visible_tables, sql_string, cursor);
441  return hints;
442 }
443 
444 std::vector<std::string> Calcite::get_db_objects(const std::string ra) {
445  std::vector<std::string> v_db_obj;
446  Document document;
447  document.Parse(ra.c_str());
448  const Value& rels = document["rels"];
449  CHECK(rels.IsArray());
450  for (auto& v : rels.GetArray()) {
451  std::string relOp(v["relOp"].GetString());
452  if (!relOp.compare("EnumerableTableScan")) {
453  std::string x;
454  auto t = v["table"].GetArray();
455  x = t[1].GetString();
456  v_db_obj.push_back(x);
457  }
458  }
459 
460  return v_db_obj;
461 }
462 
464  query_state::QueryStateProxy query_state_proxy,
465  const std::string sql_string,
466  const std::vector<TFilterPushDownInfo>& filter_push_down_info,
467  const bool legacy_syntax,
468  const bool is_explain,
469  const bool is_view_optimize,
470  const std::string& calcite_session_id) {
471  query_state::Timer timer = query_state_proxy.createTimer(__func__);
472  const auto& user_session_info = query_state_proxy.getQueryState().getConstSessionInfo();
473  const auto& cat = user_session_info->getCatalog();
474  const std::string user = getInternalSessionProxyUserName();
475  const std::string catalog = cat.getCurrentDB().dbName;
476  LOG(INFO) << "User " << user << " catalog " << catalog << " sql '" << sql_string << "'";
477  LOG(IR) << "SQL query\n" << sql_string << "\nEnd of SQL query";
478  LOG(PTX) << "SQL query\n" << sql_string << "\nEnd of SQL query";
479 
480  TPlanResult ret;
481  if (server_available_) {
482  try {
483  // calcite_session_id would be an empty string when accessed by internal resources
484  // that would not access `process` through handler instance, like for eg: Unit
485  // Tests. In these cases we would use the session_id from query state.
486  auto ms = measure<>::execution([&]() {
487  auto clientP = getClient(remote_calcite_port_);
488  clientP.first->process(ret,
489  user,
490  calcite_session_id.empty()
491  ? user_session_info->get_session_id()
492  : calcite_session_id,
493  catalog,
494  sql_string,
495  filter_push_down_info,
496  legacy_syntax,
497  is_explain,
498  is_view_optimize);
499  clientP.second->close();
500  });
501 
502  // LOG(INFO) << ret.plan_result;
503  LOG(INFO) << "Time in Thrift "
504  << (ms > ret.execution_time_ms ? ms - ret.execution_time_ms : 0)
505  << " (ms), Time in Java Calcite server " << ret.execution_time_ms
506  << " (ms)";
507  } catch (InvalidParseRequest& e) {
508  throw std::invalid_argument(e.whyUp);
509  } catch (const std::exception& ex) {
510  LOG(FATAL)
511  << "Error occurred trying to communicate with Calcite server, the error was: '"
512  << ex.what() << "', omnisci_server restart will be required";
513  return ret; // satisfy return-type warning
514  }
515  } else {
516  LOG(FATAL) << "Not routing to Calcite, server is not up";
517  }
518  return ret;
519 }
520 
522  if (server_available_) {
523  TPlanResult ret;
524  std::string whitelist;
525 
526  auto clientP = getClient(remote_calcite_port_);
527  clientP.first->getExtensionFunctionWhitelist(whitelist);
528  clientP.second->close();
529  VLOG(1) << whitelist;
530  return whitelist;
531  } else {
532  LOG(FATAL) << "Not routing to Calcite, server is not up";
533  return "";
534  }
535  CHECK(false);
536  return "";
537 }
538 
540  if (server_available_) {
541  TPlanResult ret;
542  std::string whitelist;
543 
544  auto clientP = getClient(remote_calcite_port_);
545  clientP.first->getUserDefinedFunctionWhitelist(whitelist);
546  clientP.second->close();
547  VLOG(1) << "User defined functions whitelist loaded from Calcite: " << whitelist;
548  return whitelist;
549  } else {
550  LOG(FATAL) << "Not routing to Calcite, server is not up";
551  return "";
552  }
553  UNREACHABLE();
554  return "";
555 }
556 
558  std::call_once(shutdown_once_flag_,
559  [this, log]() { this->inner_close_calcite_server(log); });
560 }
561 
563  if (server_available_) {
564  LOG_IF(INFO, log) << "Shutting down Calcite server";
565  try {
566  auto clientP = getClient(remote_calcite_port_);
567  clientP.first->shutdown();
568  clientP.second->close();
569  } catch (const std::exception& e) {
570  if (std::string(e.what()) != "connect() failed: Connection refused" &&
571  std::string(e.what()) != "socket open() error: Connection refused" &&
572  std::string(e.what()) != "No more data to read.") {
573  std::cerr << "Error shutting down Calcite server: " << e.what() << std::endl;
574  } // else Calcite already shut down
575  }
576  LOG_IF(INFO, log) << "shut down Calcite";
577  server_available_ = false;
578  }
579 }
580 
582  close_calcite_server(false);
583 }
584 
586  if (server_available_) {
587  TPlanResult ret;
588  std::string whitelist;
589  auto clientP = getClient(remote_calcite_port_);
590  clientP.first->getRuntimeExtensionFunctionWhitelist(whitelist);
591  clientP.second->close();
592  VLOG(1) << "Runtime extension functions whitelist loaded from Calcite: " << whitelist;
593  return whitelist;
594  } else {
595  LOG(FATAL) << "Not routing to Calcite, server is not up";
596  return "";
597  }
598  UNREACHABLE();
599  return "";
600 }
601 
603  const std::vector<TUserDefinedFunction>& udfs,
604  const std::vector<TUserDefinedTableFunction>& udtfs) {
605  if (server_available_) {
606  auto clientP = getClient(remote_calcite_port_);
607  clientP.first->setRuntimeExtensionFunctions(udfs, udtfs);
608  clientP.second->close();
609  } else {
610  LOG(FATAL) << "Not routing to Calcite, server is not up";
611  }
612 }
std::vector< std::string > get_db_objects(const std::string ra)
Definition: Calcite.cpp:444
int wrapped_execlp(char const *path, XDEBUG_OPTION &&x_debug, REMOTE_DEBUG_OPTION &&remote_debug, REMAINING_ARGS &&...standard_args)
Definition: Calcite.cpp:55
std::string cat(Ts &&...args)
std::once_flag shutdown_once_flag_
Definition: Calcite.h:135
class for a per-database catalog. also includes metadata for the current database and the current use...
Definition: Catalog.h:86
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:293
#define LOG(tag)
Definition: Logger.h:188
mapd::shared_ptr< ThriftClientConnection > connMgr_
Definition: Calcite.h:124
std::string mapd_root_abs_path()
Definition: mapdpath.h:30
static const AccessPrivileges INSERT_INTO_TABLE
Definition: DBObject.h:161
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:463
#define UNREACHABLE()
Definition: Logger.h:241
bool hasAny() const
Definition: DBObject.h:140
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:160
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:333
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:204
static SysCatalog & instance()
Definition: SysCatalog.h:256
CHECK(cgen_state)
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
void setRuntimeExtensionFunctions(const std::vector< TUserDefinedFunction > &udfs, const std::vector< TUserDefinedTableFunction > &udtfs)
Definition: Calcite.cpp:602
const DBMetadata & getCurrentDB() const
Definition: Catalog.h:182
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:428
QueryState & getQueryState()
Definition: QueryState.h:172
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 std::string &udf_filename="")
Definition: Calcite.cpp:283
static const AccessPrivileges DELETE_FROM_TABLE
Definition: DBObject.h:163
int ping(int retry_num=0, int max_retry=50)
Definition: Calcite.cpp:266
std::string getUserDefinedFunctionWhitelist()
Definition: Calcite.cpp:539
std::string get_session_id() const
Definition: SessionInfo.h:73
static const AccessPrivileges SELECT_FROM_VIEW
Definition: DBObject.h:180
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:382
int remote_calcite_port_
Definition: Calcite.h:127
int32_t dbId
Definition: DBObject.h:56
std::string const getInternalSessionProxyUserName()
Definition: Calcite.h:96
void inner_close_calcite_server(bool log)
Definition: Calcite.cpp:562
bool server_available_
Definition: Calcite.h:125
bool g_enable_watchdog false
Definition: Execute.cpp:73
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:162
void checkAccessedObjectsPrivileges(query_state::QueryStateProxy query_state_prox, TPlanResult plan) const
Definition: Calcite.cpp:404
std::shared_ptr< Catalog_Namespace::SessionInfo const > getConstSessionInfo() const
Definition: QueryState.cpp:77
~Calcite()
Definition: Calcite.cpp:581
std::string getExtensionFunctionWhitelist()
Definition: Calcite.cpp:521
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:186
void checkPermissionForTables(const Catalog_Namespace::SessionInfo &session_info, std::vector< std::string > tableOrViewNames, AccessPrivileges tablePrivs, AccessPrivileges viewPrivs)
Definition: Calcite.cpp:346
std::string getRuntimeExtensionFunctionWhitelist()
Definition: Calcite.cpp:585
#define VLOG(n)
Definition: Logger.h:291
void close_calcite_server(bool log=true)
Definition: Calcite.cpp:557