OmniSciDB  95562058bd
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CreateForeignTableCommand Class Reference

#include <DdlCommandExecutor.h>

+ Inheritance diagram for CreateForeignTableCommand:
+ Collaboration diagram for CreateForeignTableCommand:

Public Member Functions

 CreateForeignTableCommand (const rapidjson::Value &ddl_payload, std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)
 
void execute (TQueryResult &_return) override
 
- Public Member Functions inherited from DdlCommand
 DdlCommand (const rapidjson::Value &ddl_payload, std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)
 

Private Member Functions

void setTableDetails (const std::string &table_name, TableDescriptor &td, const size_t column_count)
 
void setColumnDetails (std::list< ColumnDescriptor > &columns)
 
void setRefreshOptions (foreign_storage::ForeignTable &foreign_table)
 

Additional Inherited Members

- Protected Member Functions inherited from DdlCommand
bool isDefaultServer (const std::string &server_name)
 
- Protected Attributes inherited from DdlCommand
const rapidjson::Value & ddl_payload_
 
std::shared_ptr
< Catalog_Namespace::SessionInfo
const > 
session_ptr_
 

Detailed Description

Definition at line 113 of file DdlCommandExecutor.h.

Constructor & Destructor Documentation

CreateForeignTableCommand::CreateForeignTableCommand ( const rapidjson::Value &  ddl_payload,
std::shared_ptr< Catalog_Namespace::SessionInfo const >  session_ptr 
)

Definition at line 516 of file DdlCommandExecutor.cpp.

References CHECK.

519  : DdlCommand(ddl_payload, session_ptr) {
520  CHECK(ddl_payload.HasMember("serverName"));
521  CHECK(ddl_payload["serverName"].IsString());
522  CHECK(ddl_payload.HasMember("tableName"));
523  CHECK(ddl_payload["tableName"].IsString());
524  CHECK(ddl_payload.HasMember("ifNotExists"));
525  CHECK(ddl_payload["ifNotExists"].IsBool());
526  CHECK(ddl_payload.HasMember("columns"));
527  CHECK(ddl_payload["columns"].IsArray());
528 }
DdlCommand(const rapidjson::Value &ddl_payload, std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)
#define CHECK(condition)
Definition: Logger.h:197

Member Function Documentation

void CreateForeignTableCommand::execute ( TQueryResult &  _return)
overridevirtual

Executes the DDL command corresponding to provided JSON payload.

Parameters
_returnresult of DDL command execution (if applicable)

Implements DdlCommand.

Definition at line 530 of file DdlCommandExecutor.cpp.

References AccessPrivileges::CREATE_TABLE, Catalog_Namespace::SysCatalog::createDBObject(), DdlCommand::ddl_payload_, Catalog_Namespace::SysCatalog::instance(), DdlCommand::session_ptr_, setColumnDetails(), setTableDetails(), and TableDBObjectType.

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

530  {
531  auto& catalog = session_ptr_->getCatalog();
532 
533  const std::string& table_name = ddl_payload_["tableName"].GetString();
534  if (!session_ptr_->checkDBAccessPrivileges(DBObjectType::TableDBObjectType,
536  throw std::runtime_error(
537  "Foreign table \"" + table_name +
538  "\" will not be created. User has no CREATE TABLE privileges.");
539  }
540 
541  bool if_not_exists = ddl_payload_["ifNotExists"].GetBool();
542  if (!catalog.validateNonExistentTableOrView(table_name, if_not_exists)) {
543  return;
544  }
545 
546  foreign_storage::ForeignTable foreign_table{};
547  std::list<ColumnDescriptor> columns{};
548  setColumnDetails(columns);
549  setTableDetails(table_name, foreign_table, columns.size());
550  catalog.createTable(foreign_table, columns, {}, true);
551 
552  // TODO (max): It's transactionally unsafe, should be fixed: we may create object w/o
553  // privileges
555  session_ptr_->get_currentUser(),
556  foreign_table.tableName,
558  catalog);
559 }
void createDBObject(const UserMetadata &user, const std::string &objectName, DBObjectType type, const Catalog_Namespace::Catalog &catalog, int32_t objectId=-1)
static SysCatalog & instance()
Definition: SysCatalog.h:286
void setColumnDetails(std::list< ColumnDescriptor > &columns)
static const AccessPrivileges CREATE_TABLE
Definition: DBObject.h:159
void setTableDetails(const std::string &table_name, TableDescriptor &td, const size_t column_count)
const rapidjson::Value & ddl_payload_
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:

void CreateForeignTableCommand::setColumnDetails ( std::list< ColumnDescriptor > &  columns)
private

Definition at line 629 of file DdlCommandExecutor.cpp.

References CHECK, DdlCommand::ddl_payload_, ddl_utils::set_column_descriptor(), ddl_utils::validate_non_duplicate_column(), and ddl_utils::validate_non_reserved_keyword().

Referenced by execute().

629  {
630  std::unordered_set<std::string> column_names{};
631  for (auto& column_def : ddl_payload_["columns"].GetArray()) {
632  CHECK(column_def.IsObject());
633  CHECK(column_def.HasMember("name"));
634  CHECK(column_def["name"].IsString());
635  const std::string& column_name = column_def["name"].GetString();
636 
637  CHECK(column_def.HasMember("dataType"));
638  CHECK(column_def["dataType"].IsObject());
639 
640  JsonColumnSqlType sql_type{column_def["dataType"]};
641  const auto& data_type = column_def["dataType"].GetObject();
642  CHECK(data_type.HasMember("notNull"));
643  CHECK(data_type["notNull"].IsBool());
644 
645  std::unique_ptr<JsonColumnEncoding> encoding;
646  if (data_type.HasMember("encoding") && !data_type["encoding"].IsNull()) {
647  CHECK(data_type["encoding"].IsObject());
648  encoding = std::make_unique<JsonColumnEncoding>(column_def["dataType"]);
649  }
650 
651  ColumnDescriptor cd;
652  ddl_utils::validate_non_duplicate_column(column_name, column_names);
655  column_name, cd, &sql_type, data_type["notNull"].GetBool(), encoding.get());
656  columns.emplace_back(cd);
657  }
658 }
void validate_non_duplicate_column(const std::string &column_name, std::unordered_set< std::string > &upper_column_names)
Definition: DdlUtils.cpp:520
void validate_non_reserved_keyword(const std::string &column_name)
Definition: DdlUtils.cpp:529
specifies the content in-memory of a row in the column metadata table
void set_column_descriptor(const std::string &column_name, ColumnDescriptor &cd, SqlType *column_type, const bool not_null, const Encoding *encoding)
Definition: DdlUtils.cpp:492
#define CHECK(condition)
Definition: Logger.h:197
const rapidjson::Value & ddl_payload_

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void CreateForeignTableCommand::setRefreshOptions ( foreign_storage::ForeignTable foreign_table)
private

Definition at line 606 of file DdlCommandExecutor.cpp.

References foreign_storage::ForeignTable::ALL_REFRESH_UPDATE_TYPE, foreign_storage::ForeignTable::MANUAL_REFRESH_TIMING_TYPE, foreign_storage::OptionsContainer::options, foreign_storage::ForeignTable::REFRESH_TIMING_TYPE_KEY, foreign_storage::ForeignTable::REFRESH_UPDATE_TYPE_KEY, and to_upper().

Referenced by setTableDetails().

607  {
608  auto refresh_timing_entry =
610  if (refresh_timing_entry == foreign_table.options.end()) {
613  } else {
615  to_upper(refresh_timing_entry->second);
616  }
617 
618  auto update_type_entry =
620  if (update_type_entry == foreign_table.options.end()) {
623  } else {
625  to_upper(update_type_entry->second);
626  }
627 }
std::map< std::string, std::string, std::less<> > options
static constexpr const char * MANUAL_REFRESH_TIMING_TYPE
Definition: ForeignTable.h:36
static constexpr const char * REFRESH_UPDATE_TYPE_KEY
Definition: ForeignTable.h:32
std::string to_upper(const std::string &str)
static constexpr const char * ALL_REFRESH_UPDATE_TYPE
Definition: ForeignTable.h:33
static constexpr const char * REFRESH_TIMING_TYPE_KEY
Definition: ForeignTable.h:29

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void CreateForeignTableCommand::setTableDetails ( const std::string &  table_name,
TableDescriptor td,
const size_t  column_count 
)
private

Definition at line 561 of file DdlCommandExecutor.cpp.

References CHECK, foreign_storage::DataWrapperType::CSV, DdlCommand::ddl_payload_, StorageType::FOREIGN_TABLE, TableDescriptor::fragments, foreign_storage::ParquetDataWrapper::getSupportedOptions(), foreign_storage::CsvDataWrapper::getSupportedOptions(), TableDescriptor::hasDeletedCol, TableDescriptor::keyMetainfo, foreign_storage::DataWrapperType::PARQUET, TableDescriptor::partitions, DdlCommand::session_ptr_, ddl_utils::set_default_table_attributes(), setRefreshOptions(), TableDescriptor::storageType, TableDescriptor::userId, foreign_storage::ParquetDataWrapper::validateOptions(), and foreign_storage::CsvDataWrapper::validateOptions().

Referenced by execute().

563  {
564  ddl_utils::set_default_table_attributes(table_name, td, column_count);
565  td.userId = session_ptr_->get_currentUser().userId;
567  td.hasDeletedCol = false;
568  td.keyMetainfo = "[]";
569  td.fragments = "";
570  td.partitions = "";
571 
572  auto& foreign_table = dynamic_cast<foreign_storage::ForeignTable&>(td);
573  const std::string server_name = ddl_payload_["serverName"].GetString();
574  foreign_table.foreign_server = session_ptr_->getCatalog().getForeignServer(server_name);
575  if (!foreign_table.foreign_server) {
576  throw std::runtime_error{"Foreign server with name \"" + server_name +
577  "\" does not exist."};
578  }
579 
580  if (ddl_payload_.HasMember("options") && !ddl_payload_["options"].IsNull()) {
581  CHECK(ddl_payload_["options"].IsObject());
582  foreign_table.populateOptionsMap(ddl_payload_["options"]);
583  setRefreshOptions(foreign_table);
584 
585  std::vector<std::string_view> supported_data_wrapper_options;
586  if (foreign_table.foreign_server->data_wrapper_type ==
589  supported_data_wrapper_options =
591  } else if (foreign_table.foreign_server->data_wrapper_type ==
594  supported_data_wrapper_options =
596  }
597  foreign_table.validate(supported_data_wrapper_options);
598  }
599 
600  if (const auto it = foreign_table.options.find("FRAGMENT_SIZE");
601  it != foreign_table.options.end()) {
602  foreign_table.maxFragRows = std::stoi(it->second);
603  }
604 }
std::string partitions
static std::vector< std::string_view > getSupportedOptions()
static std::vector< std::string_view > getSupportedOptions()
static void validateOptions(const ForeignTable *foreign_table)
std::string storageType
void setRefreshOptions(foreign_storage::ForeignTable &foreign_table)
std::string fragments
std::string keyMetainfo
void set_default_table_attributes(const std::string &table_name, TableDescriptor &td, const int32_t column_count)
Definition: DdlUtils.cpp:506
#define CHECK(condition)
Definition: Logger.h:197
static constexpr char const * CSV
Definition: ForeignServer.h:35
const rapidjson::Value & ddl_payload_
static void validateOptions(const ForeignTable *foreign_table)
std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr_
static constexpr char const * FOREIGN_TABLE
static constexpr char const * PARQUET
Definition: ForeignServer.h:36

+ 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: