OmniSciDB  72c90bc290
 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 1396 of file ParserNode.h.

Constructor & Destructor Documentation

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

Definition at line 1398 of file ParserNode.h.

1398 : table_(tab), param_(p) {}
std::unique_ptr< std::string > table_
Definition: ParserNode.h:1403
std::unique_ptr< NameValueAssign > param_
Definition: ParserNode.h:1404

Member Function Documentation

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

Implements Parser::DDLStmt.

Definition at line 5635 of file ParserNode.cpp.

References Parser::check_alter_table_privilege(), Executor::clearExternalCaches(), Parser::IntLiteral::get_intval(), Catalog_Namespace::SessionInfo::getCatalog(), legacylockmgr::getExecuteReadLock(), TableDescriptor::isView, param_, table_, table_is_temporary(), TableDescriptor::tableId, to_lower(), and UNREACHABLE.

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

5636  {
5637  if (read_only_mode) {
5638  throw std::runtime_error("ALTER TABLE invalid in read only mode.");
5639  }
5640  enum TableParamType { MaxRollbackEpochs, Epoch, MaxRows };
5641  static const std::unordered_map<std::string, TableParamType> param_map = {
5642  {"max_rollback_epochs", TableParamType::MaxRollbackEpochs},
5643  {"epoch", TableParamType::Epoch},
5644  {"max_rows", TableParamType::MaxRows}};
5645  const auto execute_read_lock = legacylockmgr::getExecuteReadLock();
5646  auto& catalog = session.getCatalog();
5647  const auto td_with_lock =
5649  catalog, *table_, false);
5650  const auto td = td_with_lock();
5651  if (!td) {
5652  throw std::runtime_error("Table " + *table_ + " does not exist.");
5653  }
5654  if (td->isView) {
5655  throw std::runtime_error("Setting parameters for a view is not supported.");
5656  }
5657  if (table_is_temporary(td)) {
5658  throw std::runtime_error(
5659  "Setting parameters for a temporary table is not yet supported.");
5660  }
5661  check_alter_table_privilege(session, td);
5662 
5663  // invalidate cached item
5664  Executor::clearExternalCaches(true, td, catalog.getDatabaseId());
5665 
5666  std::string param_name(*param_->get_name());
5667  boost::algorithm::to_lower(param_name);
5668  const IntLiteral* val_int_literal =
5669  dynamic_cast<const IntLiteral*>(param_->get_value());
5670  if (val_int_literal == nullptr) {
5671  throw std::runtime_error("Table parameters should be integers.");
5672  }
5673  const int64_t param_val = val_int_literal->get_intval();
5674 
5675  const auto param_it = param_map.find(param_name);
5676  if (param_it == param_map.end()) {
5677  throw std::runtime_error(param_name + " is not a settable table parameter.");
5678  }
5679  switch (param_it->second) {
5680  case MaxRollbackEpochs: {
5681  catalog.setMaxRollbackEpochs(td->tableId, param_val);
5682  break;
5683  }
5684  case Epoch: {
5685  catalog.setTableEpoch(catalog.getDatabaseId(), td->tableId, param_val);
5686  break;
5687  }
5688  case MaxRows: {
5689  catalog.setMaxRows(td->tableId, param_val);
5690  break;
5691  }
5692  default: {
5693  UNREACHABLE() << "Unexpected TableParamType value: " << param_it->second
5694  << ", key: " << param_it->first;
5695  }
5696  }
5697 }
std::string to_lower(const std::string &str)
auto getExecuteReadLock()
#define UNREACHABLE()
Definition: Logger.h:338
std::unique_ptr< std::string > table_
Definition: ParserNode.h:1403
std::unique_ptr< NameValueAssign > param_
Definition: ParserNode.h:1404
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
static void clearExternalCaches(bool for_update, const TableDescriptor *td, const int current_db_id)
Definition: Execute.h:438

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

Referenced by execute().

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

Definition at line 1403 of file ParserNode.h.

Referenced by execute().


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