OmniSciDB  1dac507f6e
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Calcite.cpp File Reference
#include "Calcite.h"
#include "Catalog/Catalog.h"
#include "Shared/ConfigResolve.h"
#include "Shared/Logger.h"
#include "Shared/MapDParameters.h"
#include "Shared/ThriftClient.h"
#include "Shared/fixautotools.h"
#include "Shared/mapd_shared_ptr.h"
#include "Shared/mapdpath.h"
#include "Shared/measure.h"
#include "ThriftHandler/QueryState.h"
#include <thrift/protocol/TBinaryProtocol.h>
#include <thrift/transport/TSocket.h>
#include <thrift/transport/TTransportUtils.h>
#include <type_traits>
#include "gen-cpp/CalciteServer.h"
#include "rapidjson/document.h"
#include <utility>
+ Include dependency graph for Calcite.cpp:

Go to the source code of this file.

Namespaces

 anonymous_namespace{Calcite.cpp}
 

Functions

template<typename XDEBUG_OPTION , typename REMOTE_DEBUG_OPTION , typename... REMAINING_ARGS>
int anonymous_namespace{Calcite.cpp}::wrapped_execlp (char const *path, XDEBUG_OPTION &&x_debug, REMOTE_DEBUG_OPTION &&remote_debug, REMAINING_ARGS &&...standard_args)
 
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, const std::string &ssl_keystore, const std::string &ssl_keystore_password, const std::string &ssl_key_file, const std::string &ssl_cert_file, const std::string &udf_filename)
 
void checkPermissionForTables (const Catalog_Namespace::SessionInfo &session_info, std::vector< std::string > tableOrViewNames, AccessPrivileges tablePrivs, AccessPrivileges viewPrivs)
 

Function Documentation

void checkPermissionForTables ( const Catalog_Namespace::SessionInfo session_info,
std::vector< std::string >  tableOrViewNames,
AccessPrivileges  tablePrivs,
AccessPrivileges  viewPrivs 
)

Definition at line 328 of file Calcite.cpp.

References DBObjectKey::dbId, Catalog_Namespace::DBMetadata::dbId, Catalog_Namespace::SessionInfo::get_currentUser(), Catalog_Namespace::SessionInfo::getCatalog(), Catalog_Namespace::Catalog::getCurrentDB(), Catalog_Namespace::Catalog::getMetadataForTable(), AccessPrivileges::hasAny(), Catalog_Namespace::SysCatalog::instance(), TableDescriptor::isView, DBObjectKey::objectId, DBObjectKey::permissionType, TableDBObjectType, TableDescriptor::tableId, TableDescriptor::userId, Catalog_Namespace::UserMetadata::userName, and ViewDBObjectType.

Referenced by Calcite::process().

331  {
332  Catalog_Namespace::Catalog& catalog = session_info.getCatalog();
333 
334  for (auto tableOrViewName : tableOrViewNames) {
335  const TableDescriptor* tableMeta =
336  catalog.getMetadataForTable(tableOrViewName, false);
337 
338  if (!tableMeta) {
339  throw std::runtime_error("unknown table of view: " + tableOrViewName);
340  }
341 
342  DBObjectKey key;
343  key.dbId = catalog.getCurrentDB().dbId;
346  key.objectId = tableMeta->tableId;
347  AccessPrivileges privs = tableMeta->isView ? viewPrivs : tablePrivs;
348  DBObject dbobject(key, privs, tableMeta->userId);
349  std::vector<DBObject> privObjects{dbobject};
350 
351  if (!privs.hasAny()) {
352  throw std::runtime_error("Operation not supported for object " + tableOrViewName);
353  }
354 
355  if (!Catalog_Namespace::SysCatalog::instance().checkPrivileges(
356  session_info.get_currentUser(), privObjects)) {
357  throw std::runtime_error("Violation of access privileges: user " +
358  session_info.get_currentUser().userName +
359  " has no proper privileges for object " + tableOrViewName);
360  }
361  }
362 }
class for a per-database catalog. also includes metadata for the current database and the current use...
Definition: Catalog.h:81
bool hasAny() const
Definition: DBObject.h:133
int32_t objectId
Definition: DBObject.h:56
static SysCatalog & instance()
Definition: SysCatalog.h:242
const DBMetadata & getCurrentDB() const
Definition: Catalog.h:176
Catalog & getCatalog() const
Definition: SessionInfo.h:90
int32_t dbId
Definition: DBObject.h:55
int32_t permissionType
Definition: DBObject.h:54
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
const UserMetadata & get_currentUser() const
Definition: SessionInfo.h:93

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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,
const std::string &  ssl_keystore,
const std::string &  ssl_keystore_password,
const std::string &  ssl_key_file,
const std::string &  ssl_cert_file,
const std::string &  udf_filename 
)
static

Definition at line 68 of file Calcite.cpp.

References logger::FATAL, logger::INFO, LOG, mapd_root_abs_path(), to_string(), and anonymous_namespace{Calcite.cpp}::wrapped_execlp().

Referenced by Calcite::runServer().

78  {
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 mapdKeyStoreP = "-Y";
97  std::string mapdKeyStorePasswdP = "-Z";
98  std::string mapdLogDirectory = "-DMAPD_LOG_DIR=" + data_dir;
99  std::string userDefinedFunctionsP = "";
100  std::string userDefinedFunctionsD = "";
101 
102  if (!udf_filename.empty()) {
103  userDefinedFunctionsP += "-u";
104  userDefinedFunctionsD += udf_filename;
105  }
106 
107  int pid = fork();
108  if (pid == 0) {
109  int i;
110 
111  if (udf_filename.empty()) {
112  i = wrapped_execlp("java",
113  xDebug.c_str(),
114  remoteDebug.c_str(),
115  xmxP.c_str(),
116  mapdLogDirectory.c_str(),
117  jarP.c_str(),
118  jarD.c_str(),
119  extensionsP.c_str(),
120  extensionsD.c_str(),
121  dataP.c_str(),
122  dataD.c_str(),
123  localPortP.c_str(),
124  localPortD.c_str(),
125  mapdPortP.c_str(),
126  mapdPortD.c_str(),
127  mapdTrustStoreP.c_str(),
128  ssl_trust_store.c_str(),
129  mapdTrustPasswdP.c_str(),
130  ssl_trust_password.c_str(),
131  mapdKeyStoreP.c_str(),
132  ssl_keystore.c_str(),
133  mapdKeyStorePasswdP.c_str(),
134  ssl_keystore_password.c_str(),
135  (char*)0);
136  } else {
137  i = wrapped_execlp("java",
138  xDebug.c_str(),
139  remoteDebug.c_str(),
140  xmxP.c_str(),
141  mapdLogDirectory.c_str(),
142  jarP.c_str(),
143  jarD.c_str(),
144  extensionsP.c_str(),
145  extensionsD.c_str(),
146  dataP.c_str(),
147  dataD.c_str(),
148  localPortP.c_str(),
149  localPortD.c_str(),
150  mapdPortP.c_str(),
151  mapdPortD.c_str(),
152  mapdTrustStoreP.c_str(),
153  ssl_trust_store.c_str(),
154  mapdTrustPasswdP.c_str(),
155  ssl_trust_password.c_str(),
156  mapdKeyStoreP.c_str(),
157  ssl_keystore.c_str(),
158  mapdKeyStorePasswdP.c_str(),
159  ssl_keystore_password.c_str(),
160  userDefinedFunctionsP.c_str(),
161  userDefinedFunctionsD.c_str(),
162  (char*)0);
163  }
164 
165  if (i) {
166  int errsv = errno;
167  LOG(FATAL) << "Failed to start Calcite server [errno=" << errsv
168  << "]: " << strerror(errsv);
169  } else {
170  LOG(INFO) << "Successfully started Calcite server";
171  }
172  }
173 }
int wrapped_execlp(char const *path, XDEBUG_OPTION &&x_debug, REMOTE_DEBUG_OPTION &&remote_debug, REMAINING_ARGS &&...standard_args)
Definition: Calcite.cpp:56
#define LOG(tag)
Definition: Logger.h:185
std::string mapd_root_abs_path()
Definition: mapdpath.h:30
std::string to_string(char const *&&v)

+ Here is the call graph for this function:

+ Here is the caller graph for this function: