OmniSciDB  06b3bd477c
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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)
 
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

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

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

Implements Parser::DDLStmt.

Definition at line 3155 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.

3155  {
3156  auto& catalog = session.getCatalog();
3157 
3158  // TODO: Removal of the FileMgr is not thread safe. Take a global system write lock when
3159  // truncating a table
3160  const auto execute_write_lock = mapd_unique_lock<mapd_shared_mutex>(
3163 
3164  const auto td_with_lock =
3166  catalog, *table, true);
3167  const auto td = td_with_lock();
3168  if (!td) {
3169  throw std::runtime_error("Table " + *table + " does not exist.");
3170  }
3171 
3172  // check access privileges
3173  std::vector<DBObject> privObjects;
3174  DBObject dbObject(*table, TableDBObjectType);
3175  dbObject.loadKey(catalog);
3176  dbObject.setPrivileges(AccessPrivileges::TRUNCATE_TABLE);
3177  privObjects.push_back(dbObject);
3178  if (!SysCatalog::instance().checkPrivileges(session.get_currentUser(), privObjects)) {
3179  throw std::runtime_error("Table " + *table + " will not be truncated. User " +
3180  session.get_currentUser().userName +
3181  " has no proper privileges.");
3182  }
3183 
3184  if (td->isView) {
3185  throw std::runtime_error(*table + " is a view. Cannot Truncate.");
3186  }
3187  auto table_data_write_lock =
3189  catalog.truncateTable(td);
3190 
3191  // invalidate cached hashtable
3193 }
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
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
const UserMetadata & get_currentUser() const
Definition: SessionInfo.h:68

+ Here is the call graph for this function:

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

Definition at line 1157 of file ParserNode.h.

References table.

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

Member Data Documentation

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

Definition at line 1161 of file ParserNode.h.

Referenced by get_table().


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