OmniSciDB  c0231cc57d
 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 56 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 660 of file DdlCommandExecutor.cpp.

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

663  : DdlCommand(ddl_data, session_ptr) {
664  if (!g_enable_fsi) {
665  throw std::runtime_error("Unsupported command: CREATE FOREIGN SERVER");
666  }
667  auto& ddl_payload = extractPayload(ddl_data_);
668  CHECK(ddl_payload.HasMember("serverName"));
669  CHECK(ddl_payload["serverName"].IsString());
670  CHECK(ddl_payload.HasMember("dataWrapper"));
671  CHECK(ddl_payload["dataWrapper"].IsString());
672  if (ddl_payload.HasMember("options")) {
673  CHECK(ddl_payload["options"].IsObject());
674  }
675  CHECK(ddl_payload.HasMember("ifNotExists"));
676  CHECK(ddl_payload["ifNotExists"].IsBool());
677 }
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:222
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 679 of file DdlCommandExecutor.cpp.

References AccessPrivileges::CREATE_SERVER, Catalog_Namespace::SysCatalog::createDBObject(), DdlCommand::ddl_data_, anonymous_namespace{DdlCommandExecutor.cpp}::extractPayload(), 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().

679  {
681 
682  if (read_only_mode) {
683  throw std::runtime_error("CREATE FOREIGN SERVER invalid in read only mode.");
684  }
685  auto& ddl_payload = extractPayload(ddl_data_);
686  std::string server_name = ddl_payload["serverName"].GetString();
687  if (is_default_server(server_name)) {
689  }
690  bool if_not_exists = ddl_payload["ifNotExists"].GetBool();
691  if (session_ptr_->getCatalog().getForeignServer(server_name)) {
692  if (if_not_exists) {
693  return result;
694  } else {
695  throw std::runtime_error{"A foreign server with name \"" + server_name +
696  "\" already exists."};
697  }
698  }
699  // check access privileges
700  if (!session_ptr_->checkDBAccessPrivileges(DBObjectType::ServerDBObjectType,
702  throw std::runtime_error("Server " + std::string(server_name) +
703  " will not be created. User has no create privileges.");
704  }
705 
706  auto& current_user = session_ptr_->get_currentUser();
707  auto foreign_server = std::make_unique<foreign_storage::ForeignServer>();
708  foreign_server->data_wrapper_type = to_upper(ddl_payload["dataWrapper"].GetString());
709  foreign_server->name = server_name;
710  foreign_server->user_id = current_user.userId;
711  if (ddl_payload.HasMember("options")) {
712  foreign_server->populateOptionsMap(ddl_payload["options"]);
713  }
714  foreign_server->validate();
715 
716  auto& catalog = session_ptr_->getCatalog();
717  catalog.createForeignServer(std::move(foreign_server),
718  ddl_payload["ifNotExists"].GetBool());
720  current_user, server_name, ServerDBObjectType, catalog);
721 
722  return result;
723 }
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:341
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)
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: