OmniSciDB  ba1bac9284
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
AlterForeignTableCommand Class Reference

#include <DdlCommandExecutor.h>

+ Inheritance diagram for AlterForeignTableCommand:
+ Collaboration diagram for AlterForeignTableCommand:

Public Member Functions

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

Private Member Functions

void alterOptions (const foreign_storage::ForeignTable *foreign_table)
 
void renameTable (const foreign_storage::ForeignTable *foreign_table)
 
void renameColumn (const 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 DdlCommandDataddl_data_
 
std::shared_ptr
< Catalog_Namespace::SessionInfo
const
session_ptr_
 

Detailed Description

Definition at line 114 of file DdlCommandExecutor.h.

Constructor & Destructor Documentation

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

Definition at line 1344 of file DdlCommandExecutor.cpp.

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

1347  : DdlCommand(ddl_data, session_ptr) {
1348  auto& ddl_payload = extractPayload(ddl_data_);
1349  CHECK(ddl_payload.HasMember("tableName"));
1350  CHECK(ddl_payload["tableName"].IsString());
1351  CHECK(ddl_payload.HasMember("alterType"));
1352  CHECK(ddl_payload["alterType"].IsString());
1353  if (ddl_payload["alterType"] == "RENAME_TABLE") {
1354  CHECK(ddl_payload.HasMember("newTableName"));
1355  CHECK(ddl_payload["newTableName"].IsString());
1356  } else if (ddl_payload["alterType"] == "RENAME_COLUMN") {
1357  CHECK(ddl_payload.HasMember("oldColumnName"));
1358  CHECK(ddl_payload["oldColumnName"].IsString());
1359  CHECK(ddl_payload.HasMember("newColumnName"));
1360  CHECK(ddl_payload["newColumnName"].IsString());
1361  } else if (ddl_payload["alterType"] == "ALTER_OPTIONS") {
1362  CHECK(ddl_payload.HasMember("options"));
1363  CHECK(ddl_payload["options"].IsObject());
1364  } else {
1365  UNREACHABLE() << "Not a valid alter foreign table command: "
1366  << ddl_payload["alterType"].GetString();
1367  }
1368 }
#define UNREACHABLE()
Definition: Logger.h:250
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:206

+ Here is the call graph for this function:

Member Function Documentation

void AlterForeignTableCommand::alterOptions ( const foreign_storage::ForeignTable foreign_table)
private

Definition at line 1439 of file DdlCommandExecutor.cpp.

References cat(), foreign_storage::ForeignTable::createOptionsMap(), DdlCommand::ddl_data_, anonymous_namespace{DdlCommandExecutor.cpp}::extractPayload(), DdlCommand::session_ptr_, foreign_storage::ForeignTable::validateAlterOptions(), and foreign_storage::ForeignTable::validateSupportedOptionKeys().

Referenced by execute().

1440  {
1441  auto& ddl_payload = extractPayload(ddl_data_);
1442  const std::string& table_name = ddl_payload["tableName"].GetString();
1443  auto& cat = session_ptr_->getCatalog();
1444  auto new_options_map =
1445  foreign_storage::ForeignTable::createOptionsMap(ddl_payload["options"]);
1446  foreign_table->validateSupportedOptionKeys(new_options_map);
1448  cat.setForeignTableOptions(table_name, new_options_map, false);
1449 }
static void validateAlterOptions(const OptionsMap &options_map)
Verifies that the given options map only contains options that can be legally altered.
std::string cat(Ts &&...args)
void validateSupportedOptionKeys(const OptionsMap &options_map) const
Verifies that the options_map contains the keys required by a foreign table; including those specifie...
static OptionsMap createOptionsMap(const rapidjson::Value &json_options)
Creates an options map from given options. Converts options that must be upper case appropriately...
const DdlCommandData & ddl_data_
const rapidjson::Value & extractPayload(const DdlCommandData &ddl_data)
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:

ExecutionResult AlterForeignTableCommand::execute ( )
overridevirtual

Executes the DDL command corresponding to provided JSON payload.

Parameters
_returnresult of DDL command execution (if applicable)

Implements DdlCommand.

Definition at line 1370 of file DdlCommandExecutor.cpp.

References AccessPrivileges::ALTER_TABLE, alterOptions(), CHECK, DdlCommand::ddl_data_, anonymous_namespace{DdlCommandExecutor.cpp}::extractPayload(), ddl_utils::FOREIGN_TABLE, lockmgr::TableLockMgrImpl< TableDataLockMgr >::getWriteLockForTable(), renameColumn(), renameTable(), DdlCommand::session_ptr_, TableDBObjectType, and ddl_utils::validate_table_type().

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

1370  {
1371  auto& ddl_payload = extractPayload(ddl_data_);
1372  auto& catalog = session_ptr_->getCatalog();
1373  const std::string& table_name = ddl_payload["tableName"].GetString();
1374  auto [td, td_with_lock] =
1375  get_table_descriptor_with_lock<lockmgr::WriteLock>(catalog, table_name, false);
1376 
1378 
1379  if (!session_ptr_->checkDBAccessPrivileges(
1381  throw std::runtime_error(
1382  "Current user does not have the privilege to alter foreign table: " + table_name);
1383  }
1384 
1385  auto table_data_write_lock =
1387  auto foreign_table = dynamic_cast<const foreign_storage::ForeignTable*>(td);
1388  CHECK(foreign_table);
1389 
1390  std::string alter_type = ddl_payload["alterType"].GetString();
1391  if (alter_type == "RENAME_TABLE") {
1392  renameTable(foreign_table);
1393  } else if (alter_type == "RENAME_COLUMN") {
1394  renameColumn(foreign_table);
1395  } else if (alter_type == "ALTER_OPTIONS") {
1396  alterOptions(foreign_table);
1397  }
1398 
1399  return ExecutionResult();
1400 }
static const AccessPrivileges ALTER_TABLE
Definition: DBObject.h:167
static WriteLock getWriteLockForTable(const Catalog_Namespace::Catalog &cat, const std::string &table_name)
Definition: LockMgrImpl.h:155
const DdlCommandData & ddl_data_
const rapidjson::Value & extractPayload(const DdlCommandData &ddl_data)
void alterOptions(const foreign_storage::ForeignTable *foreign_table)
void validate_table_type(const TableDescriptor *td, const TableType expected_table_type, const std::string &command)
Definition: DdlUtils.cpp:554
void renameTable(const foreign_storage::ForeignTable *foreign_table)
#define CHECK(condition)
Definition: Logger.h:206
std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr_
void renameColumn(const foreign_storage::ForeignTable *foreign_table)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void AlterForeignTableCommand::renameColumn ( const foreign_storage::ForeignTable foreign_table)
private

Definition at line 1417 of file DdlCommandExecutor.cpp.

References cat(), DdlCommand::ddl_data_, anonymous_namespace{DdlCommandExecutor.cpp}::extractPayload(), DdlCommand::session_ptr_, and TableDescriptor::tableId.

Referenced by execute().

1418  {
1419  auto& ddl_payload = extractPayload(ddl_data_);
1420  auto& cat = session_ptr_->getCatalog();
1421  const std::string& old_column_name = ddl_payload["oldColumnName"].GetString();
1422  const std::string& new_column_name = ddl_payload["newColumnName"].GetString();
1423  auto column = cat.getMetadataForColumn(foreign_table->tableId, old_column_name);
1424  if (!column) {
1425  throw std::runtime_error("Column with name \"" + old_column_name +
1426  "\" can not be renamed to \"" + new_column_name + "\". " +
1427  "Column with name \"" + old_column_name +
1428  "\" does not exist.");
1429  }
1430  if (cat.getMetadataForColumn(foreign_table->tableId, new_column_name)) {
1431  throw std::runtime_error("Column with name \"" + old_column_name +
1432  "\" can not be renamed to \"" + new_column_name + "\". " +
1433  "A column with name \"" + new_column_name +
1434  "\" already exists.");
1435  }
1436  cat.renameColumn(foreign_table, column, new_column_name);
1437 }
std::string cat(Ts &&...args)
const DdlCommandData & ddl_data_
const rapidjson::Value & extractPayload(const DdlCommandData &ddl_data)
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 AlterForeignTableCommand::renameTable ( const foreign_storage::ForeignTable foreign_table)
private

Definition at line 1402 of file DdlCommandExecutor.cpp.

References cat(), DdlCommand::ddl_data_, anonymous_namespace{DdlCommandExecutor.cpp}::extractPayload(), and DdlCommand::session_ptr_.

Referenced by execute().

1403  {
1404  auto& ddl_payload = extractPayload(ddl_data_);
1405  auto& cat = session_ptr_->getCatalog();
1406  const std::string& table_name = ddl_payload["tableName"].GetString();
1407  const std::string& new_table_name = ddl_payload["newTableName"].GetString();
1408  if (cat.getForeignTable(new_table_name)) {
1409  throw std::runtime_error("Foreign table with name \"" + table_name +
1410  "\" can not be renamed to \"" + new_table_name + "\". " +
1411  "A different table with name \"" + new_table_name +
1412  "\" already exists.");
1413  }
1414  cat.renameTable(foreign_table, new_table_name);
1415 }
std::string cat(Ts &&...args)
const DdlCommandData & ddl_data_
const rapidjson::Value & extractPayload(const DdlCommandData &ddl_data)
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: