OmniSciDB  ba1bac9284
 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 1192 of file ParserNode.h.

Constructor & Destructor Documentation

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

Definition at line 1194 of file ParserNode.h.

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

Member Function Documentation

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

Implements Parser::DDLStmt.

Definition at line 3825 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(), test_readcsv::table, TableDBObjectType, AccessPrivileges::TRUNCATE_TABLE, Catalog_Namespace::UserMetadata::userLoggable(), and foreign_storage::validate_non_foreign_table_write().

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

3825  {
3826  auto& catalog = session.getCatalog();
3827 
3828  // TODO: Removal of the FileMgr is not thread safe. Take a global system write lock
3829  // when truncating a table
3830  const auto execute_write_lock = mapd_unique_lock<mapd_shared_mutex>(
3833 
3834  const auto td_with_lock =
3836  catalog, *table, true);
3837  const auto td = td_with_lock();
3838  if (!td) {
3839  throw std::runtime_error("Table " + *table + " does not exist.");
3840  }
3841 
3842  // check access privileges
3843  std::vector<DBObject> privObjects;
3844  DBObject dbObject(*table, TableDBObjectType);
3845  dbObject.loadKey(catalog);
3846  dbObject.setPrivileges(AccessPrivileges::TRUNCATE_TABLE);
3847  privObjects.push_back(dbObject);
3848  if (!SysCatalog::instance().checkPrivileges(session.get_currentUser(), privObjects)) {
3849  throw std::runtime_error("Table " + *table + " will not be truncated. User " +
3850  session.get_currentUser().userLoggable() +
3851  " has no proper privileges.");
3852  }
3853 
3854  if (td->isView) {
3855  throw std::runtime_error(*table + " is a view. Cannot Truncate.");
3856  }
3858  auto table_data_write_lock =
3860  catalog.truncateTable(td);
3861 
3862  // invalidate cached hashtable
3864 }
void validate_non_foreign_table_write(const TableDescriptor *table_descriptor)
Definition: FsiUtils.h:22
static const AccessPrivileges TRUNCATE_TABLE
Definition: DBObject.h:166
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::unique_ptr< std::string > table
Definition: ParserNode.h:1199
std::string userLoggable() const
Definition: SysCatalog.cpp:125
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 1195 of file ParserNode.h.

References table.

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

Member Data Documentation

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

Definition at line 1199 of file ParserNode.h.

Referenced by get_table().


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