OmniSciDB  eb3a3d0a03
 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) 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 1378 of file ParserNode.h.

Constructor & Destructor Documentation

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

Definition at line 1380 of file ParserNode.h.

1380 : table_(tab), param_(p) {}
std::unique_ptr< std::string > table_
Definition: ParserNode.h:1384
std::unique_ptr< NameValueAssign > param_
Definition: ParserNode.h:1385

Member Function Documentation

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

Implements Parser::DDLStmt.

Definition at line 4534 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(), TableDescriptor::isView, param_, table_, table_is_temporary(), TableDescriptor::tableId, to_lower(), and UNREACHABLE.

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

4534  {
4535  enum TableParamType { MaxRollbackEpochs, Epoch, MaxRows };
4536  static const std::unordered_map<std::string, TableParamType> param_map = {
4537  {"max_rollback_epochs", TableParamType::MaxRollbackEpochs},
4538  {"epoch", TableParamType::Epoch},
4539  {"max_rows", TableParamType::MaxRows}};
4540  // Below is to ensure that executor is not currently executing on table when we might be
4541  // changing it's storage. Question: will/should catalog write lock take care of this?
4542  const auto execute_write_lock = mapd_unique_lock<mapd_shared_mutex>(
4545  auto& catalog = session.getCatalog();
4546  const auto td_with_lock =
4548  catalog, *table_, false);
4549  const auto td = td_with_lock();
4550  if (!td) {
4551  throw std::runtime_error("Table " + *table_ + " does not exist.");
4552  }
4553  if (td->isView) {
4554  throw std::runtime_error("Setting parameters for a view is not supported.");
4555  }
4556  if (table_is_temporary(td)) {
4557  throw std::runtime_error(
4558  "Setting parameters for a temporary table is not yet supported.");
4559  }
4560  check_alter_table_privilege(session, td);
4561 
4562  std::string param_name(*param_->get_name());
4563  boost::algorithm::to_lower(param_name);
4564  const IntLiteral* val_int_literal =
4565  dynamic_cast<const IntLiteral*>(param_->get_value());
4566  if (val_int_literal == nullptr) {
4567  throw std::runtime_error("Table parameters should be integers.");
4568  }
4569  const int64_t param_val = val_int_literal->get_intval();
4570 
4571  const auto param_it = param_map.find(param_name);
4572  if (param_it == param_map.end()) {
4573  throw std::runtime_error(param_name + " is not a settable table parameter.");
4574  }
4575  switch (param_it->second) {
4576  case MaxRollbackEpochs: {
4577  catalog.setMaxRollbackEpochs(td->tableId, param_val);
4578  break;
4579  }
4580  case Epoch: {
4581  catalog.setTableEpoch(catalog.getDatabaseId(), td->tableId, param_val);
4582  break;
4583  }
4584  case MaxRows: {
4585  catalog.setMaxRows(td->tableId, param_val);
4586  break;
4587  }
4588  default: {
4589  UNREACHABLE() << "Unexpected TableParamType value: " << param_it->second
4590  << ", key: " << param_it->first;
4591  }
4592  }
4593 }
std::string to_lower(const std::string &str)
#define UNREACHABLE()
Definition: Logger.h:253
std::unique_ptr< std::string > table_
Definition: ParserNode.h:1384
std::unique_ptr< NameValueAssign > param_
Definition: ParserNode.h:1385
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:67
static std::shared_ptr< MutexType > getMutex(const LockType lockType, const KeyType &key)
Definition: LegacyLockMgr.h:51

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

Referenced by execute().

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

Definition at line 1384 of file ParserNode.h.

Referenced by execute().


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