OmniSciDB  cde582ebc3
 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 5248 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().

5249  {
5250  if (read_only_mode) {
5251  throw std::runtime_error("ALTER TABLE invalid in read only mode.");
5252  }
5253  enum TableParamType { MaxRollbackEpochs, Epoch, MaxRows };
5254  static const std::unordered_map<std::string, TableParamType> param_map = {
5255  {"max_rollback_epochs", TableParamType::MaxRollbackEpochs},
5256  {"epoch", TableParamType::Epoch},
5257  {"max_rows", TableParamType::MaxRows}};
5258  const auto execute_read_lock =
5262  auto& catalog = session.getCatalog();
5263  const auto td_with_lock =
5265  catalog, *table_, false);
5266  const auto td = td_with_lock();
5267  if (!td) {
5268  throw std::runtime_error("Table " + *table_ + " does not exist.");
5269  }
5270  if (td->isView) {
5271  throw std::runtime_error("Setting parameters for a view is not supported.");
5272  }
5273  if (table_is_temporary(td)) {
5274  throw std::runtime_error(
5275  "Setting parameters for a temporary table is not yet supported.");
5276  }
5277  check_alter_table_privilege(session, td);
5278 
5279  // invalidate cached item
5280  std::vector<int> table_key{catalog.getCurrentDB().dbId, td->tableId};
5281  ResultSetCacheInvalidator::invalidateCachesByTable(boost::hash_value(table_key));
5282 
5283  std::string param_name(*param_->get_name());
5284  boost::algorithm::to_lower(param_name);
5285  const IntLiteral* val_int_literal =
5286  dynamic_cast<const IntLiteral*>(param_->get_value());
5287  if (val_int_literal == nullptr) {
5288  throw std::runtime_error("Table parameters should be integers.");
5289  }
5290  const int64_t param_val = val_int_literal->get_intval();
5291 
5292  const auto param_it = param_map.find(param_name);
5293  if (param_it == param_map.end()) {
5294  throw std::runtime_error(param_name + " is not a settable table parameter.");
5295  }
5296  switch (param_it->second) {
5297  case MaxRollbackEpochs: {
5298  catalog.setMaxRollbackEpochs(td->tableId, param_val);
5299  break;
5300  }
5301  case Epoch: {
5302  catalog.setTableEpoch(catalog.getDatabaseId(), td->tableId, param_val);
5303  break;
5304  }
5305  case MaxRows: {
5306  catalog.setMaxRows(td->tableId, param_val);
5307  break;
5308  }
5309  default: {
5310  UNREACHABLE() << "Unexpected TableParamType value: " << param_it->second
5311  << ", key: " << param_it->first;
5312  }
5313  }
5314 }
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: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

+ 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: