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

#include <ParserNode.h>

+ Inheritance diagram for Parser::AlterTableParamStmt:
+ Collaboration diagram for Parser::AlterTableParamStmt:

Public Member Functions

 AlterTableParamStmt (std::string *tab, NameValueAssign *p)
 
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_
 
std::unique_ptr< NameValueAssignparam_
 

Detailed Description

Definition at line 1409 of file ParserNode.h.

Constructor & Destructor Documentation

Parser::AlterTableParamStmt::AlterTableParamStmt ( std::string *  tab,
NameValueAssign p 
)
inline

Definition at line 1411 of file ParserNode.h.

1411 : table_(tab), param_(p) {}
std::unique_ptr< std::string > table_
Definition: ParserNode.h:1416
std::unique_ptr< NameValueAssign > param_
Definition: ParserNode.h:1417

Member Function Documentation

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

Implements Parser::DDLStmt.

Definition at line 5326 of file ParserNode.cpp.

References Parser::check_alter_table_privilege(), legacylockmgr::ExecutorOuterLock, Parser::IntLiteral::get_intval(), Catalog_Namespace::SessionInfo::getCatalog(), legacylockmgr::LockMgr< MutexType, KeyType >::getMutex(), CacheInvalidator< CACHE_HOLDING_TYPES >::invalidateCachesByTable(), TableDescriptor::isView, param_, table_, table_is_temporary(), TableDescriptor::tableId, to_lower(), and UNREACHABLE.

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

5327  {
5328  if (read_only_mode) {
5329  throw std::runtime_error("ALTER TABLE invalid in read only mode.");
5330  }
5331  enum TableParamType { MaxRollbackEpochs, Epoch, MaxRows };
5332  static const std::unordered_map<std::string, TableParamType> param_map = {
5333  {"max_rollback_epochs", TableParamType::MaxRollbackEpochs},
5334  {"epoch", TableParamType::Epoch},
5335  {"max_rows", TableParamType::MaxRows}};
5336  const auto execute_read_lock =
5340  auto& catalog = session.getCatalog();
5341  const auto td_with_lock =
5343  catalog, *table_, false);
5344  const auto td = td_with_lock();
5345  if (!td) {
5346  throw std::runtime_error("Table " + *table_ + " does not exist.");
5347  }
5348  if (td->isView) {
5349  throw std::runtime_error("Setting parameters for a view is not supported.");
5350  }
5351  if (table_is_temporary(td)) {
5352  throw std::runtime_error(
5353  "Setting parameters for a temporary table is not yet supported.");
5354  }
5355  check_alter_table_privilege(session, td);
5356 
5357  // invalidate cached item
5358  std::vector<int> table_key{catalog.getCurrentDB().dbId, td->tableId};
5359  ResultSetCacheInvalidator::invalidateCachesByTable(boost::hash_value(table_key));
5360 
5361  std::string param_name(*param_->get_name());
5362  boost::algorithm::to_lower(param_name);
5363  const IntLiteral* val_int_literal =
5364  dynamic_cast<const IntLiteral*>(param_->get_value());
5365  if (val_int_literal == nullptr) {
5366  throw std::runtime_error("Table parameters should be integers.");
5367  }
5368  const int64_t param_val = val_int_literal->get_intval();
5369 
5370  const auto param_it = param_map.find(param_name);
5371  if (param_it == param_map.end()) {
5372  throw std::runtime_error(param_name + " is not a settable table parameter.");
5373  }
5374  switch (param_it->second) {
5375  case MaxRollbackEpochs: {
5376  catalog.setMaxRollbackEpochs(td->tableId, param_val);
5377  break;
5378  }
5379  case Epoch: {
5380  catalog.setTableEpoch(catalog.getDatabaseId(), td->tableId, param_val);
5381  break;
5382  }
5383  case MaxRows: {
5384  catalog.setMaxRows(td->tableId, param_val);
5385  break;
5386  }
5387  default: {
5388  UNREACHABLE() << "Unexpected TableParamType value: " << param_it->second
5389  << ", key: " << param_it->first;
5390  }
5391  }
5392 }
static std::shared_ptr< WrapperType< MutexType > > getMutex(const LockType lockType, const KeyType &key)
static void invalidateCachesByTable(size_t table_key)
std::string to_lower(const std::string &str)
#define UNREACHABLE()
Definition: Logger.h:337
std::unique_ptr< std::string > table_
Definition: ParserNode.h:1416
std::shared_lock< T > shared_lock
std::unique_ptr< NameValueAssign > param_
Definition: ParserNode.h:1417
void check_alter_table_privilege(const Catalog_Namespace::SessionInfo &session, const TableDescriptor *td)
Definition: Epoch.h:30
bool table_is_temporary(const TableDescriptor *const td)
Catalog & getCatalog() const
Definition: SessionInfo.h:75

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

std::unique_ptr<NameValueAssign> Parser::AlterTableParamStmt::param_
private

Definition at line 1417 of file ParserNode.h.

Referenced by execute().

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

Definition at line 1416 of file ParserNode.h.

Referenced by execute().


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