OmniSciDB  d2f719934e
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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 1476 of file DdlCommandExecutor.cpp.

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

1479  : DdlCommand(ddl_data, session_ptr) {
1480  auto& ddl_payload = extractPayload(ddl_data_);
1481  CHECK(ddl_payload.HasMember("tableName"));
1482  CHECK(ddl_payload["tableName"].IsString());
1483  CHECK(ddl_payload.HasMember("alterType"));
1484  CHECK(ddl_payload["alterType"].IsString());
1485  if (ddl_payload["alterType"] == "RENAME_TABLE") {
1486  CHECK(ddl_payload.HasMember("newTableName"));
1487  CHECK(ddl_payload["newTableName"].IsString());
1488  } else if (ddl_payload["alterType"] == "RENAME_COLUMN") {
1489  CHECK(ddl_payload.HasMember("oldColumnName"));
1490  CHECK(ddl_payload["oldColumnName"].IsString());
1491  CHECK(ddl_payload.HasMember("newColumnName"));
1492  CHECK(ddl_payload["newColumnName"].IsString());
1493  } else if (ddl_payload["alterType"] == "ALTER_OPTIONS") {
1494  CHECK(ddl_payload.HasMember("options"));
1495  CHECK(ddl_payload["options"].IsObject());
1496  } else {
1497  UNREACHABLE() << "Not a valid alter foreign table command: "
1498  << ddl_payload["alterType"].GetString();
1499  }
1500 }
#define UNREACHABLE()
Definition: Logger.h:255
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:211

+ Here is the call graph for this function:

Member Function Documentation

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

Definition at line 1571 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().

1572  {
1573  auto& ddl_payload = extractPayload(ddl_data_);
1574  const std::string& table_name = ddl_payload["tableName"].GetString();
1575  auto& cat = session_ptr_->getCatalog();
1576  auto new_options_map =
1577  foreign_storage::ForeignTable::createOptionsMap(ddl_payload["options"]);
1578  foreign_table->validateSupportedOptionKeys(new_options_map);
1580  cat.setForeignTableOptions(table_name, new_options_map, false);
1581 }
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 1502 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().

1502  {
1503  auto& ddl_payload = extractPayload(ddl_data_);
1504  auto& catalog = session_ptr_->getCatalog();
1505  const std::string& table_name = ddl_payload["tableName"].GetString();
1506  auto [td, td_with_lock] =
1507  get_table_descriptor_with_lock<lockmgr::WriteLock>(catalog, table_name, false);
1508 
1510 
1511  if (!session_ptr_->checkDBAccessPrivileges(
1513  throw std::runtime_error(
1514  "Current user does not have the privilege to alter foreign table: " + table_name);
1515  }
1516 
1517  auto table_data_write_lock =
1519  auto foreign_table = dynamic_cast<const foreign_storage::ForeignTable*>(td);
1520  CHECK(foreign_table);
1521 
1522  std::string alter_type = ddl_payload["alterType"].GetString();
1523  if (alter_type == "RENAME_TABLE") {
1524  renameTable(foreign_table);
1525  } else if (alter_type == "RENAME_COLUMN") {
1526  renameColumn(foreign_table);
1527  } else if (alter_type == "ALTER_OPTIONS") {
1528  alterOptions(foreign_table);
1529  }
1530 
1531  return ExecutionResult();
1532 }
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:692
void renameTable(const foreign_storage::ForeignTable *foreign_table)
#define CHECK(condition)
Definition: Logger.h:211
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 1549 of file DdlCommandExecutor.cpp.

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

Referenced by execute().

1550  {
1551  auto& ddl_payload = extractPayload(ddl_data_);
1552  auto& cat = session_ptr_->getCatalog();
1553  const std::string& old_column_name = ddl_payload["oldColumnName"].GetString();
1554  const std::string& new_column_name = ddl_payload["newColumnName"].GetString();
1555  auto column = cat.getMetadataForColumn(foreign_table->tableId, old_column_name);
1556  if (!column) {
1557  throw std::runtime_error("Column with name \"" + old_column_name +
1558  "\" can not be renamed to \"" + new_column_name + "\". " +
1559  "Column with name \"" + old_column_name +
1560  "\" does not exist.");
1561  }
1562  if (cat.getMetadataForColumn(foreign_table->tableId, new_column_name)) {
1563  throw std::runtime_error("Column with name \"" + old_column_name +
1564  "\" can not be renamed to \"" + new_column_name + "\". " +
1565  "A column with name \"" + new_column_name +
1566  "\" already exists.");
1567  }
1568  cat.renameColumn(foreign_table, column, new_column_name);
1569 }
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 1534 of file DdlCommandExecutor.cpp.

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

Referenced by execute().

1535  {
1536  auto& ddl_payload = extractPayload(ddl_data_);
1537  auto& cat = session_ptr_->getCatalog();
1538  const std::string& table_name = ddl_payload["tableName"].GetString();
1539  const std::string& new_table_name = ddl_payload["newTableName"].GetString();
1540  if (cat.getForeignTable(new_table_name)) {
1541  throw std::runtime_error("Foreign table with name \"" + table_name +
1542  "\" can not be renamed to \"" + new_table_name + "\". " +
1543  "A different table with name \"" + new_table_name +
1544  "\" already exists.");
1545  }
1546  cat.renameTable(foreign_table, new_table_name);
1547 }
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: