OmniSciDB  eb3a3d0a03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Parser::TruncateTableStmt Class Reference

#include <ParserNode.h>

+ Inheritance diagram for Parser::TruncateTableStmt:
+ Collaboration diagram for Parser::TruncateTableStmt:

Public Member Functions

 TruncateTableStmt (std::string *tab)
 
 TruncateTableStmt (const rapidjson::Value &payload)
 
const std::string * get_table () const
 
void execute (const Catalog_Namespace::SessionInfo &session) override
 
- Public Member Functions inherited from Parser::DDLStmt
void setColumnDescriptor (ColumnDescriptor &cd, const ColumnDef *coldef)
 
- Public Member Functions inherited from Parser::Node
virtual ~Node ()
 

Private Attributes

std::unique_ptr< std::string > table_
 

Detailed Description

Definition at line 1220 of file ParserNode.h.

Constructor & Destructor Documentation

Parser::TruncateTableStmt::TruncateTableStmt ( std::string *  tab)
inline

Definition at line 1222 of file ParserNode.h.

1222 : table_(tab) {}
std::unique_ptr< std::string > table_
Definition: ParserNode.h:1228
Parser::TruncateTableStmt::TruncateTableStmt ( const rapidjson::Value &  payload)

Definition at line 3866 of file ParserNode.cpp.

References CHECK, json_str(), and table_.

3866  {
3867  CHECK(payload.HasMember("tableName"));
3868  table_ = std::make_unique<std::string>(json_str(payload["tableName"]));
3869 }
std::unique_ptr< std::string > table_
Definition: ParserNode.h:1228
const std::string json_str(const rapidjson::Value &obj) noexcept
Definition: JsonAccessors.h:44
#define CHECK(condition)
Definition: Logger.h:209

+ Here is the call graph for this function:

Member Function Documentation

void Parser::TruncateTableStmt::execute ( const Catalog_Namespace::SessionInfo session)
overridevirtual

Implements Parser::DDLStmt.

Definition at line 3871 of file ParserNode.cpp.

References legacylockmgr::ExecutorOuterLock, Catalog_Namespace::SessionInfo::get_currentUser(), Catalog_Namespace::SessionInfo::getCatalog(), legacylockmgr::LockMgr< MutexType, KeyType >::getMutex(), lockmgr::TableLockMgrImpl< TableDataLockMgr >::getWriteLockForTable(), CacheInvalidator< CACHE_HOLDING_TYPES >::invalidateCaches(), TableDescriptor::isView, DBObject::loadKey(), DBObject::setPrivileges(), table_, TableDBObjectType, AccessPrivileges::TRUNCATE_TABLE, Catalog_Namespace::UserMetadata::userLoggable(), and foreign_storage::validate_non_foreign_table_write().

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

3871  {
3872  auto& catalog = session.getCatalog();
3873 
3874  // TODO: Removal of the FileMgr is not thread safe. Take a global system write lock
3875  // when truncating a table
3876  const auto execute_write_lock = mapd_unique_lock<mapd_shared_mutex>(
3879 
3880  const auto td_with_lock =
3882  catalog, *table_, true);
3883  const auto td = td_with_lock();
3884  if (!td) {
3885  throw std::runtime_error("Table " + *table_ + " does not exist.");
3886  }
3887 
3888  // check access privileges
3889  std::vector<DBObject> privObjects;
3890  DBObject dbObject(*table_, TableDBObjectType);
3891  dbObject.loadKey(catalog);
3892  dbObject.setPrivileges(AccessPrivileges::TRUNCATE_TABLE);
3893  privObjects.push_back(dbObject);
3894  if (!SysCatalog::instance().checkPrivileges(session.get_currentUser(), privObjects)) {
3895  throw std::runtime_error("Table " + *table_ + " will not be truncated. User " +
3896  session.get_currentUser().userLoggable() +
3897  " has no proper privileges.");
3898  }
3899 
3900  if (td->isView) {
3901  throw std::runtime_error(*table_ + " is a view. Cannot Truncate.");
3902  }
3904  auto table_data_write_lock =
3906  catalog.truncateTable(td);
3907 
3908  // invalidate cached hashtable
3910 }
void validate_non_foreign_table_write(const TableDescriptor *table_descriptor)
Definition: FsiUtils.h:22
static const AccessPrivileges TRUNCATE_TABLE
Definition: DBObject.h:166
std::unique_ptr< std::string > table_
Definition: ParserNode.h:1228
static WriteLock getWriteLockForTable(const Catalog_Namespace::Catalog &cat, const std::string &table_name)
Definition: LockMgrImpl.h:155
static void invalidateCaches()
Catalog & getCatalog() const
Definition: SessionInfo.h:67
static std::shared_ptr< MutexType > getMutex(const LockType lockType, const KeyType &key)
Definition: LegacyLockMgr.h:51
std::string userLoggable() const
Definition: SysCatalog.cpp:126
const UserMetadata & get_currentUser() const
Definition: SessionInfo.h:73

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

const std::string* Parser::TruncateTableStmt::get_table ( ) const
inline

Definition at line 1224 of file ParserNode.h.

References table_.

1224 { return table_.get(); }
std::unique_ptr< std::string > table_
Definition: ParserNode.h:1228

Member Data Documentation

std::unique_ptr<std::string> Parser::TruncateTableStmt::table_
private

Definition at line 1228 of file ParserNode.h.

Referenced by execute(), get_table(), and TruncateTableStmt().


The documentation for this class was generated from the following files: