OmniSciDB  dfae7c3b14
Parser::TruncateTableStmt Class Reference

#include <ParserNode.h>

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

Public Member Functions

 TruncateTableStmt (std::string *tab)
 
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 1154 of file ParserNode.h.

Constructor & Destructor Documentation

◆ TruncateTableStmt()

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

Definition at line 1156 of file ParserNode.h.

1156 : table(tab) {}
std::unique_ptr< std::string > table
Definition: ParserNode.h:1161

Member Function Documentation

◆ execute()

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

Implements Parser::DDLStmt.

Definition at line 3143 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(), DBObject::loadKey(), DBObject::setPrivileges(), TableDBObjectType, AccessPrivileges::TRUNCATE_TABLE, and Catalog_Namespace::UserMetadata::userName.

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

3143  {
3144  auto& catalog = session.getCatalog();
3145 
3146  // TODO: Removal of the FileMgr is not thread safe. Take a global system write lock when
3147  // truncating a table
3148  const auto execute_write_lock = mapd_unique_lock<mapd_shared_mutex>(
3151 
3152  const auto td_with_lock =
3154  catalog, *table, true);
3155  const auto td = td_with_lock();
3156  if (!td) {
3157  throw std::runtime_error("Table " + *table + " does not exist.");
3158  }
3159 
3160  // check access privileges
3161  std::vector<DBObject> privObjects;
3162  DBObject dbObject(*table, TableDBObjectType);
3163  dbObject.loadKey(catalog);
3164  dbObject.setPrivileges(AccessPrivileges::TRUNCATE_TABLE);
3165  privObjects.push_back(dbObject);
3166  if (!SysCatalog::instance().checkPrivileges(session.get_currentUser(), privObjects)) {
3167  throw std::runtime_error("Table " + *table + " will not be truncated. User " +
3168  session.get_currentUser().userName +
3169  " has no proper privileges.");
3170  }
3171 
3172  if (td->isView) {
3173  throw std::runtime_error(*table + " is a view. Cannot Truncate.");
3174  }
3175  auto table_data_write_lock =
3177  catalog.truncateTable(td);
3178 
3179  // invalidate cached hashtable
3181 }
static const AccessPrivileges TRUNCATE_TABLE
Definition: DBObject.h:165
static WriteLock getWriteLockForTable(const Catalog_Namespace::Catalog &cat, const std::string &table_name)
Definition: LockMgrImpl.h:155
const UserMetadata & get_currentUser() const
Definition: SessionInfo.h:68
static void invalidateCaches()
Catalog & getCatalog() const
Definition: SessionInfo.h:65
static std::shared_ptr< MutexType > getMutex(const LockType lockType, const KeyType &key)
Definition: LegacyLockMgr.h:51
std::unique_ptr< std::string > table
Definition: ParserNode.h:1161
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_table()

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

Definition at line 1157 of file ParserNode.h.

1157 { return table.get(); }
std::unique_ptr< std::string > table
Definition: ParserNode.h:1161

Member Data Documentation

◆ table

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

Definition at line 1161 of file ParserNode.h.


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