OmniSciDB  ba1bac9284
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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 1373 of file ParserNode.h.

Constructor & Destructor Documentation

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

Definition at line 1375 of file ParserNode.h.

1375 : table(tab), param(p) {}
std::unique_ptr< std::string > table
Definition: ParserNode.h:1379
std::unique_ptr< NameValueAssign > param
Definition: ParserNode.h:1380

Member Function Documentation

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

Implements Parser::DDLStmt.

Definition at line 4373 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, test_readcsv::table, table_is_temporary(), TableDescriptor::tableId, to_lower(), and UNREACHABLE.

Referenced by Parser::AlterTableStmt::delegateExecute(), and omnisci.cursor.Cursor::executemany().

4373  {
4374  enum TableParamType { MaxRollbackEpochs, Epoch, MaxRows };
4375  static const std::unordered_map<std::string, TableParamType> param_map = {
4376  {"max_rollback_epochs", TableParamType::MaxRollbackEpochs},
4377  {"epoch", TableParamType::Epoch},
4378  {"max_rows", TableParamType::MaxRows}};
4379  // Below is to ensure that executor is not currently executing on table when we might be
4380  // changing it's storage. Question: will/should catalog write lock take care of this?
4381  const auto execute_write_lock = mapd_unique_lock<mapd_shared_mutex>(
4384  auto& catalog = session.getCatalog();
4385  const auto td_with_lock =
4387  catalog, *table, false);
4388  const auto td = td_with_lock();
4389  if (!td) {
4390  throw std::runtime_error("Table " + *table + " does not exist.");
4391  }
4392  if (td->isView) {
4393  throw std::runtime_error("Setting parameters for a view is not supported.");
4394  }
4395  if (table_is_temporary(td)) {
4396  throw std::runtime_error(
4397  "Setting parameters for a temporary table is not yet supported.");
4398  }
4399  check_alter_table_privilege(session, td);
4400 
4401  std::string param_name(*param->get_name());
4402  boost::algorithm::to_lower(param_name);
4403  const IntLiteral* val_int_literal = dynamic_cast<const IntLiteral*>(param->get_value());
4404  if (val_int_literal == nullptr) {
4405  throw std::runtime_error("Table parameters should be integers.");
4406  }
4407  const int64_t param_val = val_int_literal->get_intval();
4408 
4409  const auto param_it = param_map.find(param_name);
4410  if (param_it == param_map.end()) {
4411  throw std::runtime_error(param_name + " is not a settable table parameter.");
4412  }
4413  switch (param_it->second) {
4414  case MaxRollbackEpochs: {
4415  catalog.setMaxRollbackEpochs(td->tableId, param_val);
4416  break;
4417  }
4418  case Epoch: {
4419  catalog.setTableEpoch(catalog.getDatabaseId(), td->tableId, param_val);
4420  break;
4421  }
4422  case MaxRows: {
4423  catalog.setMaxRows(td->tableId, param_val);
4424  break;
4425  }
4426  default: {
4427  UNREACHABLE() << "Unexpected TableParamType value: " << param_it->second
4428  << ", key: " << param_it->first;
4429  }
4430  }
4431 }
std::string to_lower(const std::string &str)
std::unique_ptr< std::string > table
Definition: ParserNode.h:1379
#define UNREACHABLE()
Definition: Logger.h:250
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
std::unique_ptr< NameValueAssign > param
Definition: ParserNode.h:1380

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

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

Definition at line 1379 of file ParserNode.h.


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