OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DropForeignTableCommand Class Reference

#include <DdlCommandExecutor.h>

+ Inheritance diagram for DropForeignTableCommand:
+ Collaboration diagram for DropForeignTableCommand:

Public Member Functions

 DropForeignTableCommand (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 106 of file DdlCommandExecutor.h.

Constructor & Destructor Documentation

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

Definition at line 1526 of file DdlCommandExecutor.cpp.

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

1529  : DdlCommand(ddl_data, session_ptr) {
1530  if (!g_enable_fsi) {
1531  throw std::runtime_error("Unsupported command: DROP FOREIGN TABLE");
1532  }
1533  auto& ddl_payload = extractPayload(ddl_data_);
1534  CHECK(ddl_payload.HasMember("tableName"));
1535  CHECK(ddl_payload["tableName"].IsString());
1536  CHECK(ddl_payload.HasMember("ifExists"));
1537  CHECK(ddl_payload["ifExists"].IsBool());
1538 }
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:291
bool g_enable_fsi
Definition: Catalog.cpp:96

+ Here is the call graph for this function:

Member Function Documentation

ExecutionResult DropForeignTableCommand::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 1540 of file DdlCommandExecutor.cpp.

References CHECK, Executor::clearExternalCaches(), DdlCommand::ddl_data_, AccessPrivileges::DROP_TABLE, anonymous_namespace{DdlCommandExecutor.cpp}::extractPayload(), ddl_utils::FOREIGN_TABLE, legacylockmgr::getExecuteWriteLock(), lockmgr::TableLockMgrImpl< TableDataLockMgr >::getWriteLockForTable(), DdlCommand::session_ptr_, TableDBObjectType, and ddl_utils::validate_table_type().

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

1540  {
1541  auto execute_write_lock = legacylockmgr::getExecuteWriteLock();
1542 
1543  auto& catalog = session_ptr_->getCatalog();
1544  auto& ddl_payload = extractPayload(ddl_data_);
1545 
1546  if (read_only_mode) {
1547  throw std::runtime_error("DROP FOREIGN TABLE invalid in read only mode.");
1548  }
1549  const std::string& table_name = ddl_payload["tableName"].GetString();
1550  const TableDescriptor* td{nullptr};
1551  std::unique_ptr<lockmgr::TableSchemaLockContainer<lockmgr::WriteLock>> td_with_lock;
1552 
1553  try {
1554  td_with_lock =
1555  std::make_unique<lockmgr::TableSchemaLockContainer<lockmgr::WriteLock>>(
1557  catalog, table_name, false));
1558  CHECK(td_with_lock);
1559  td = (*td_with_lock)();
1560  } catch (const std::runtime_error& e) {
1561  // TODO(Misiu): This should not just swallow any exception, it should only catch
1562  // exceptions that stem from the table not existing.
1563  if (ddl_payload["ifExists"].GetBool()) {
1564  return ExecutionResult();
1565  } else {
1566  throw e;
1567  }
1568  }
1569 
1570  CHECK(td);
1571 
1572  if (!session_ptr_->checkDBAccessPrivileges(
1574  throw std::runtime_error(
1575  "Foreign table \"" + table_name +
1576  "\" will not be dropped. User has no DROP TABLE privileges.");
1577  }
1578 
1580  auto table_data_write_lock =
1582  Executor::clearExternalCaches(false, td, catalog.getDatabaseId());
1583  catalog.dropTable(td);
1584 
1585  return ExecutionResult();
1586 }
const DdlCommandData & ddl_data_
static const AccessPrivileges DROP_TABLE
Definition: DBObject.h:159
const rapidjson::Value & extractPayload(const DdlCommandData &ddl_data)
static WriteLock getWriteLockForTable(const Catalog_Namespace::Catalog &cat, const std::string &table_name)
void validate_table_type(const TableDescriptor *td, const TableType expected_table_type, const std::string &command)
Definition: DdlUtils.cpp:745
#define CHECK(condition)
Definition: Logger.h:291
static void clearExternalCaches(bool for_update, const TableDescriptor *td, const int current_db_id)
Definition: Execute.h:438
auto getExecuteWriteLock()
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: