OmniSciDB  c0231cc57d
 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 (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)
 

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 Attributes inherited from DdlCommand
const DdlCommandDataddl_data_
 
std::shared_ptr
< Catalog_Namespace::SessionInfo
const > 
session_ptr_
 

Detailed Description

Definition at line 113 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 2011 of file DdlCommandExecutor.cpp.

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

2014  : DdlCommand(ddl_data, session_ptr) {
2015  if (!g_enable_fsi) {
2016  throw std::runtime_error("Unsupported command: ALTER FOREIGN TABLE");
2017  }
2018  auto& ddl_payload = extractPayload(ddl_data_);
2019  CHECK(ddl_payload.HasMember("tableName"));
2020  CHECK(ddl_payload["tableName"].IsString());
2021  CHECK(ddl_payload.HasMember("alterType"));
2022  CHECK(ddl_payload["alterType"].IsString());
2023  if (ddl_payload["alterType"] == "RENAME_TABLE") {
2024  CHECK(ddl_payload.HasMember("newTableName"));
2025  CHECK(ddl_payload["newTableName"].IsString());
2026  } else if (ddl_payload["alterType"] == "RENAME_COLUMN") {
2027  CHECK(ddl_payload.HasMember("oldColumnName"));
2028  CHECK(ddl_payload["oldColumnName"].IsString());
2029  CHECK(ddl_payload.HasMember("newColumnName"));
2030  CHECK(ddl_payload["newColumnName"].IsString());
2031  } else if (ddl_payload["alterType"] == "ALTER_OPTIONS") {
2032  CHECK(ddl_payload.HasMember("options"));
2033  CHECK(ddl_payload["options"].IsObject());
2034  } else {
2035  UNREACHABLE() << "Not a valid alter foreign table command: "
2036  << ddl_payload["alterType"].GetString();
2037  }
2038 }
#define UNREACHABLE()
Definition: Logger.h:266
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

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

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

2114  {
2115  auto& ddl_payload = extractPayload(ddl_data_);
2116  const std::string& table_name = ddl_payload["tableName"].GetString();
2117  auto& cat = session_ptr_->getCatalog();
2118  auto new_options_map =
2119  foreign_storage::ForeignTable::createOptionsMap(ddl_payload["options"]);
2120  foreign_table.validateSupportedOptionKeys(new_options_map);
2121  foreign_table.validateAlterOptions(new_options_map);
2122  cat.setForeignTableOptions(table_name, new_options_map, false);
2123 }
std::string cat(Ts &&...args)
void validateAlterOptions(const OptionsMap &options_map) const
Verifies that the given options map only contains options that can be legally altered.
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 ( 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 2040 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 heavydb.cursor.Cursor::executemany().

2040  {
2041  if (read_only_mode) {
2042  throw std::runtime_error("ALTER FOREIGN TABLE invalid in read only mode.");
2043  }
2044 
2045  auto& ddl_payload = extractPayload(ddl_data_);
2046  auto& catalog = session_ptr_->getCatalog();
2047  const std::string& table_name = ddl_payload["tableName"].GetString();
2048  auto [td, td_with_lock] =
2049  get_table_descriptor_with_lock<lockmgr::WriteLock>(catalog, table_name, false);
2050 
2052 
2053  if (!session_ptr_->checkDBAccessPrivileges(
2055  throw std::runtime_error(
2056  "Current user does not have the privilege to alter foreign table: " + table_name);
2057  }
2058 
2059  auto table_data_write_lock =
2061  auto foreign_table = dynamic_cast<const foreign_storage::ForeignTable*>(td);
2062  CHECK(foreign_table);
2063 
2064  std::string alter_type = ddl_payload["alterType"].GetString();
2065  if (alter_type == "RENAME_TABLE") {
2066  renameTable(foreign_table);
2067  } else if (alter_type == "RENAME_COLUMN") {
2068  renameColumn(foreign_table);
2069  } else if (alter_type == "ALTER_OPTIONS") {
2070  alterOptions(*foreign_table);
2071  }
2072 
2073  return ExecutionResult();
2074 }
void alterOptions(const foreign_storage::ForeignTable &foreign_table)
static WriteLock getWriteLockForTable(Catalog_Namespace::Catalog &cat, const std::string &table_name)
Definition: LockMgrImpl.h:225
static const AccessPrivileges ALTER_TABLE
Definition: DBObject.h:165
const DdlCommandData & ddl_data_
const rapidjson::Value & extractPayload(const DdlCommandData &ddl_data)
void validate_table_type(const TableDescriptor *td, const TableType expected_table_type, const std::string &command)
Definition: DdlUtils.cpp:708
void renameTable(const foreign_storage::ForeignTable *foreign_table)
#define CHECK(condition)
Definition: Logger.h:222
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 2091 of file DdlCommandExecutor.cpp.

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

Referenced by execute().

2092  {
2093  auto& ddl_payload = extractPayload(ddl_data_);
2094  auto& cat = session_ptr_->getCatalog();
2095  const std::string& old_column_name = ddl_payload["oldColumnName"].GetString();
2096  const std::string& new_column_name = ddl_payload["newColumnName"].GetString();
2097  auto column = cat.getMetadataForColumn(foreign_table->tableId, old_column_name);
2098  if (!column) {
2099  throw std::runtime_error("Column with name \"" + old_column_name +
2100  "\" can not be renamed to \"" + new_column_name + "\". " +
2101  "Column with name \"" + old_column_name +
2102  "\" does not exist.");
2103  }
2104  if (cat.getMetadataForColumn(foreign_table->tableId, new_column_name)) {
2105  throw std::runtime_error("Column with name \"" + old_column_name +
2106  "\" can not be renamed to \"" + new_column_name + "\". " +
2107  "A column with name \"" + new_column_name +
2108  "\" already exists.");
2109  }
2110  cat.renameColumn(foreign_table, column, new_column_name);
2111 }
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 2076 of file DdlCommandExecutor.cpp.

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

Referenced by execute().

2077  {
2078  auto& ddl_payload = extractPayload(ddl_data_);
2079  auto& cat = session_ptr_->getCatalog();
2080  const std::string& table_name = ddl_payload["tableName"].GetString();
2081  const std::string& new_table_name = ddl_payload["newTableName"].GetString();
2082  if (cat.getForeignTable(new_table_name)) {
2083  throw std::runtime_error("Foreign table with name \"" + table_name +
2084  "\" can not be renamed to \"" + new_table_name + "\". " +
2085  "A different table with name \"" + new_table_name +
2086  "\" already exists.");
2087  }
2088  cat.renameTable(foreign_table, new_table_name);
2089 }
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: