OmniSciDB  c1a53651b2
 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, bool read_only_mode) 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 1240 of file ParserNode.h.

Constructor & Destructor Documentation

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

Definition at line 1242 of file ParserNode.h.

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

Definition at line 4599 of file ParserNode.cpp.

References CHECK, json_str(), and table_.

4599  {
4600  CHECK(payload.HasMember("tableName"));
4601  table_ = std::make_unique<std::string>(json_str(payload["tableName"]));
4602 }
std::unique_ptr< std::string > table_
Definition: ParserNode.h:1249
const std::string json_str(const rapidjson::Value &obj) noexcept
Definition: JsonAccessors.h:44
#define CHECK(condition)
Definition: Logger.h:291

+ Here is the call graph for this function:

Member Function Documentation

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

Implements Parser::DDLStmt.

Definition at line 4604 of file ParserNode.cpp.

References Executor::clearExternalCaches(), legacylockmgr::ExecutorOuterLock, Catalog_Namespace::SessionInfo::get_currentUser(), Catalog_Namespace::SessionInfo::getCatalog(), legacylockmgr::LockMgr< MutexType, KeyType >::getMutex(), lockmgr::TableLockMgrImpl< TableDataLockMgr >::getReadLockForTable(), lockmgr::TableLockMgrImpl< TableDataLockMgr >::getWriteLockForTable(), 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 heavydb.cursor.Cursor::executemany().

4605  {
4606  if (read_only_mode) {
4607  throw std::runtime_error("TRUNCATE TABLE invalid in read only mode.");
4608  }
4609  const auto execute_read_lock =
4613  auto& catalog = session.getCatalog();
4614  const auto td_with_lock =
4616  catalog, *table_, true);
4617  const auto td = td_with_lock();
4618  if (!td) {
4619  throw std::runtime_error("Table " + *table_ + " does not exist.");
4620  }
4621 
4622  // check access privileges
4623  std::vector<DBObject> privObjects;
4624  DBObject dbObject(*table_, TableDBObjectType);
4625  dbObject.loadKey(catalog);
4626  dbObject.setPrivileges(AccessPrivileges::TRUNCATE_TABLE);
4627  privObjects.push_back(dbObject);
4628  if (!SysCatalog::instance().checkPrivileges(session.get_currentUser(), privObjects)) {
4629  throw std::runtime_error("Table " + *table_ + " will not be truncated. User " +
4630  session.get_currentUser().userLoggable() +
4631  " has no proper privileges.");
4632  }
4633 
4634  if (td->isView) {
4635  throw std::runtime_error(*table_ + " is a view. Cannot Truncate.");
4636  }
4638 
4639  // invalidate cached item
4640  {
4641  auto table_data_read_lock =
4643  Executor::clearExternalCaches(false, td, catalog.getCurrentDB().dbId);
4644  }
4645 
4646  auto table_data_write_lock =
4648  catalog.truncateTable(td);
4649 }
static std::shared_ptr< WrapperType< MutexType > > getMutex(const LockType lockType, const KeyType &key)
void validate_non_foreign_table_write(const TableDescriptor *table_descriptor)
Definition: FsiUtils.h:22
static const AccessPrivileges TRUNCATE_TABLE
Definition: DBObject.h:164
std::unique_ptr< std::string > table_
Definition: ParserNode.h:1249
static WriteLock getWriteLockForTable(const Catalog_Namespace::Catalog &cat, const std::string &table_name)
Definition: LockMgrImpl.h:225
std::shared_lock< T > shared_lock
Catalog & getCatalog() const
Definition: SessionInfo.h:75
static ReadLock getReadLockForTable(Catalog_Namespace::Catalog &cat, const std::string &table_name)
Definition: LockMgrImpl.h:238
static void clearExternalCaches(bool for_update, const TableDescriptor *td, const int current_db_id)
Definition: Execute.h:388
std::string userLoggable() const
Definition: SysCatalog.cpp:158
const UserMetadata & get_currentUser() const
Definition: SessionInfo.h:88

+ 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 1244 of file ParserNode.h.

References table_.

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

Member Data Documentation

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

Definition at line 1249 of file ParserNode.h.

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


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