OmniSciDB  c0231cc57d
 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 105 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 1304 of file DdlCommandExecutor.cpp.

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

1307  : DdlCommand(ddl_data, session_ptr) {
1308  if (!g_enable_fsi) {
1309  throw std::runtime_error("Unsupported command: DROP FOREIGN TABLE");
1310  }
1311  auto& ddl_payload = extractPayload(ddl_data_);
1312  CHECK(ddl_payload.HasMember("tableName"));
1313  CHECK(ddl_payload["tableName"].IsString());
1314  CHECK(ddl_payload.HasMember("ifExists"));
1315  CHECK(ddl_payload["ifExists"].IsBool());
1316 }
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

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 1318 of file DdlCommandExecutor.cpp.

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

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

1318  {
1319  auto& catalog = session_ptr_->getCatalog();
1320  auto& ddl_payload = extractPayload(ddl_data_);
1321 
1322  if (read_only_mode) {
1323  throw std::runtime_error("DROP FOREIGN TABLE invalid in read only mode.");
1324  }
1325  const std::string& table_name = ddl_payload["tableName"].GetString();
1326  const TableDescriptor* td{nullptr};
1327  std::unique_ptr<lockmgr::TableSchemaLockContainer<lockmgr::WriteLock>> td_with_lock;
1328 
1329  try {
1330  td_with_lock =
1331  std::make_unique<lockmgr::TableSchemaLockContainer<lockmgr::WriteLock>>(
1333  catalog, table_name, false));
1334  CHECK(td_with_lock);
1335  td = (*td_with_lock)();
1336  } catch (const std::runtime_error& e) {
1337  // TODO(Misiu): This should not just swallow any exception, it should only catch
1338  // exceptions that stem from the table not existing.
1339  if (ddl_payload["ifExists"].GetBool()) {
1340  return ExecutionResult();
1341  } else {
1342  throw e;
1343  }
1344  }
1345 
1346  CHECK(td);
1347 
1348  if (!session_ptr_->checkDBAccessPrivileges(
1350  throw std::runtime_error(
1351  "Foreign table \"" + table_name +
1352  "\" will not be dropped. User has no DROP TABLE privileges.");
1353  }
1354 
1356  auto table_data_write_lock =
1358  catalog.dropTable(td);
1359 
1360  // TODO(Misiu): Implement per-table cache invalidation.
1362 
1363  return ExecutionResult();
1364 }
static WriteLock getWriteLockForTable(Catalog_Namespace::Catalog &cat, const std::string &table_name)
Definition: LockMgrImpl.h:225
static void invalidateCaches()
const DdlCommandData & ddl_data_
static const AccessPrivileges DROP_TABLE
Definition: DBObject.h:159
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
#define CHECK(condition)
Definition: Logger.h:222
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: