OmniSciDB  a5dc49c757
 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 5656 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().

5657  {
5658  if (read_only_mode) {
5659  throw std::runtime_error("ALTER TABLE invalid in read only mode.");
5660  }
5661  enum TableParamType { MaxRollbackEpochs, Epoch, MaxRows };
5662  static const std::unordered_map<std::string, TableParamType> param_map = {
5663  {"max_rollback_epochs", TableParamType::MaxRollbackEpochs},
5664  {"epoch", TableParamType::Epoch},
5665  {"max_rows", TableParamType::MaxRows}};
5666  const auto execute_read_lock = legacylockmgr::getExecuteReadLock();
5667  auto& catalog = session.getCatalog();
5668  const auto td_with_lock =
5670  catalog, *table_, false);
5671  const auto td = td_with_lock();
5672  if (!td) {
5673  throw std::runtime_error("Table " + *table_ + " does not exist.");
5674  }
5675  if (td->isView) {
5676  throw std::runtime_error("Setting parameters for a view is not supported.");
5677  }
5678  if (table_is_temporary(td)) {
5679  throw std::runtime_error(
5680  "Setting parameters for a temporary table is not yet supported.");
5681  }
5682  check_alter_table_privilege(session, td);
5683 
5684  // invalidate cached item
5685  Executor::clearExternalCaches(true, td, catalog.getDatabaseId());
5686 
5687  std::string param_name(*param_->get_name());
5688  boost::algorithm::to_lower(param_name);
5689  const IntLiteral* val_int_literal =
5690  dynamic_cast<const IntLiteral*>(param_->get_value());
5691  if (val_int_literal == nullptr) {
5692  throw std::runtime_error("Table parameters should be integers.");
5693  }
5694  const int64_t param_val = val_int_literal->get_intval();
5695 
5696  const auto param_it = param_map.find(param_name);
5697  if (param_it == param_map.end()) {
5698  throw std::runtime_error(param_name + " is not a settable table parameter.");
5699  }
5700  switch (param_it->second) {
5701  case MaxRollbackEpochs: {
5702  catalog.setMaxRollbackEpochs(td->tableId, param_val);
5703  break;
5704  }
5705  case Epoch: {
5706  catalog.setTableEpoch(catalog.getDatabaseId(), td->tableId, param_val);
5707  break;
5708  }
5709  case MaxRows: {
5710  catalog.setMaxRows(td->tableId, param_val);
5711  break;
5712  }
5713  default: {
5714  UNREACHABLE() << "Unexpected TableParamType value: " << param_it->second
5715  << ", key: " << param_it->first;
5716  }
5717  }
5718 }
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: