OmniSciDB  72c90bc290
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CreateForeignServerCommand Class Reference

#include <DdlCommandExecutor.h>

+ Inheritance diagram for CreateForeignServerCommand:
+ Collaboration diagram for CreateForeignServerCommand:

Public Member Functions

 CreateForeignServerCommand (const DdlCommandData &ddl_data, std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)
 
ExecutionResult execute (bool read_only_mode) override
 
- Public Member Functions inherited from DdlCommand
 DdlCommand (const DdlCommandData &ddl_data, std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)
 

Additional Inherited Members

- Protected Attributes inherited from DdlCommand
const DdlCommandDataddl_data_
 
std::shared_ptr
< Catalog_Namespace::SessionInfo
const > 
session_ptr_
 

Detailed Description

Definition at line 57 of file DdlCommandExecutor.h.

Constructor & Destructor Documentation

CreateForeignServerCommand::CreateForeignServerCommand ( const DdlCommandData ddl_data,
std::shared_ptr< Catalog_Namespace::SessionInfo const >  session_ptr 
)

Definition at line 869 of file DdlCommandExecutor.cpp.

References CHECK, DdlCommand::ddl_data_, anonymous_namespace{DdlCommandExecutor.cpp}::extractPayload(), and g_enable_fsi.

872  : DdlCommand(ddl_data, session_ptr) {
873  if (!g_enable_fsi) {
874  throw std::runtime_error("Unsupported command: CREATE FOREIGN SERVER");
875  }
876  auto& ddl_payload = extractPayload(ddl_data_);
877  CHECK(ddl_payload.HasMember("serverName"));
878  CHECK(ddl_payload["serverName"].IsString());
879  CHECK(ddl_payload.HasMember("dataWrapper"));
880  CHECK(ddl_payload["dataWrapper"].IsString());
881  if (ddl_payload.HasMember("options")) {
882  CHECK(ddl_payload["options"].IsObject());
883  }
884  CHECK(ddl_payload.HasMember("ifNotExists"));
885  CHECK(ddl_payload["ifNotExists"].IsBool());
886 }
const DdlCommandData & ddl_data_
const rapidjson::Value & extractPayload(const DdlCommandData &ddl_data)
DdlCommand(const DdlCommandData &ddl_data, std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)
#define CHECK(condition)
Definition: Logger.h:291
bool g_enable_fsi
Definition: Catalog.cpp:96

+ Here is the call graph for this function:

Member Function Documentation

ExecutionResult CreateForeignServerCommand::execute ( bool  read_only_mode)
overridevirtual

Executes the DDL command corresponding to provided JSON payload.

Parameters
_returnresult of DDL command execution (if applicable)

Implements DdlCommand.

Definition at line 888 of file DdlCommandExecutor.cpp.

References AccessPrivileges::CREATE_SERVER, Catalog_Namespace::SysCatalog::createDBObject(), DdlCommand::ddl_data_, anonymous_namespace{DdlCommandExecutor.cpp}::extractPayload(), legacylockmgr::getExecuteWriteLock(), Catalog_Namespace::SysCatalog::instance(), anonymous_namespace{DdlCommandExecutor.cpp}::is_default_server(), run_benchmark_import::result, ServerDBObjectType, DdlCommand::session_ptr_, anonymous_namespace{DdlCommandExecutor.cpp}::throw_reserved_server_prefix_exception(), and to_upper().

Referenced by heavydb.cursor.Cursor::executemany().

888  {
889  auto execute_write_lock = legacylockmgr::getExecuteWriteLock();
890 
892 
893  if (read_only_mode) {
894  throw std::runtime_error("CREATE FOREIGN SERVER invalid in read only mode.");
895  }
896 
897  auto& ddl_payload = extractPayload(ddl_data_);
898  std::string server_name = ddl_payload["serverName"].GetString();
899  if (is_default_server(server_name)) {
901  }
902  bool if_not_exists = ddl_payload["ifNotExists"].GetBool();
903  if (session_ptr_->getCatalog().getForeignServer(server_name)) {
904  if (if_not_exists) {
905  return result;
906  } else {
907  throw std::runtime_error{"A foreign server with name \"" + server_name +
908  "\" already exists."};
909  }
910  }
911  // check access privileges
912  if (!session_ptr_->checkDBAccessPrivileges(DBObjectType::ServerDBObjectType,
914  throw std::runtime_error("Server " + std::string(server_name) +
915  " will not be created. User has no create privileges.");
916  }
917 
918  auto& current_user = session_ptr_->get_currentUser();
919  auto foreign_server = std::make_unique<foreign_storage::ForeignServer>();
920  foreign_server->data_wrapper_type = to_upper(ddl_payload["dataWrapper"].GetString());
921  foreign_server->name = server_name;
922  foreign_server->user_id = current_user.userId;
923  if (ddl_payload.HasMember("options")) {
924  foreign_server->populateOptionsMap(ddl_payload["options"]);
925  }
926  foreign_server->validate();
927 
928  auto& catalog = session_ptr_->getCatalog();
929  catalog.createForeignServer(std::move(foreign_server),
930  ddl_payload["ifNotExists"].GetBool());
932  current_user, server_name, ServerDBObjectType, catalog);
933 
934  return result;
935 }
void createDBObject(const UserMetadata &user, const std::string &objectName, DBObjectType type, const Catalog_Namespace::Catalog &catalog, int32_t objectId=-1)
const DdlCommandData & ddl_data_
bool is_default_server(const std::string &server_name)
static SysCatalog & instance()
Definition: SysCatalog.h:343
const rapidjson::Value & extractPayload(const DdlCommandData &ddl_data)
static const AccessPrivileges CREATE_SERVER
Definition: DBObject.h:188
std::string to_upper(const std::string &str)
auto getExecuteWriteLock()
std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr_

+ Here is the call graph for this function:

+ Here is the caller graph for this function:


The documentation for this class was generated from the following files: