OmniSciDB  4201147b46
 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 5234 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().

5235  {
5236  if (read_only_mode) {
5237  throw std::runtime_error("ALTER TABLE invalid in read only mode.");
5238  }
5239  enum TableParamType { MaxRollbackEpochs, Epoch, MaxRows };
5240  static const std::unordered_map<std::string, TableParamType> param_map = {
5241  {"max_rollback_epochs", TableParamType::MaxRollbackEpochs},
5242  {"epoch", TableParamType::Epoch},
5243  {"max_rows", TableParamType::MaxRows}};
5244  const auto execute_read_lock = heavyai::shared_lock<heavyai::shared_mutex>(
5247  auto& catalog = session.getCatalog();
5248  const auto td_with_lock =
5250  catalog, *table_, false);
5251  const auto td = td_with_lock();
5252  if (!td) {
5253  throw std::runtime_error("Table " + *table_ + " does not exist.");
5254  }
5255  if (td->isView) {
5256  throw std::runtime_error("Setting parameters for a view is not supported.");
5257  }
5258  if (table_is_temporary(td)) {
5259  throw std::runtime_error(
5260  "Setting parameters for a temporary table is not yet supported.");
5261  }
5262  check_alter_table_privilege(session, td);
5263 
5264  // invalidate cached item
5265  std::vector<int> table_key{catalog.getCurrentDB().dbId, td->tableId};
5266  ResultSetCacheInvalidator::invalidateCachesByTable(boost::hash_value(table_key));
5267 
5268  std::string param_name(*param_->get_name());
5269  boost::algorithm::to_lower(param_name);
5270  const IntLiteral* val_int_literal =
5271  dynamic_cast<const IntLiteral*>(param_->get_value());
5272  if (val_int_literal == nullptr) {
5273  throw std::runtime_error("Table parameters should be integers.");
5274  }
5275  const int64_t param_val = val_int_literal->get_intval();
5276 
5277  const auto param_it = param_map.find(param_name);
5278  if (param_it == param_map.end()) {
5279  throw std::runtime_error(param_name + " is not a settable table parameter.");
5280  }
5281  switch (param_it->second) {
5282  case MaxRollbackEpochs: {
5283  catalog.setMaxRollbackEpochs(td->tableId, param_val);
5284  break;
5285  }
5286  case Epoch: {
5287  catalog.setTableEpoch(catalog.getDatabaseId(), td->tableId, param_val);
5288  break;
5289  }
5290  case MaxRows: {
5291  catalog.setMaxRows(td->tableId, param_val);
5292  break;
5293  }
5294  default: {
5295  UNREACHABLE() << "Unexpected TableParamType value: " << param_it->second
5296  << ", key: " << param_it->first;
5297  }
5298  }
5299 }
static void invalidateCachesByTable(size_t table_key)
std::string to_lower(const std::string &str)
#define UNREACHABLE()
Definition: Logger.h:266
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:65
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 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: