OmniSciDB  4201147b46
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Parser::DropColumnStmt Class Reference

#include <ParserNode.h>

+ Inheritance diagram for Parser::DropColumnStmt:
+ Collaboration diagram for Parser::DropColumnStmt:

Public Member Functions

 DropColumnStmt (std::string *tab, std::list< std::string * > *cols)
 
void execute (const Catalog_Namespace::SessionInfo &session, bool read_only_mode) override
 
const std::string * get_table () const
 
- 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::list< std::unique_ptr
< std::string > > 
columns_
 

Detailed Description

Definition at line 1392 of file ParserNode.h.

Constructor & Destructor Documentation

Parser::DropColumnStmt::DropColumnStmt ( std::string *  tab,
std::list< std::string * > *  cols 
)
inline

Definition at line 1394 of file ParserNode.h.

References columns_.

1394  : table_(tab) {
1395  for (const auto col : *cols) {
1396  this->columns_.emplace_back(col);
1397  }
1398  delete cols;
1399  }
std::list< std::unique_ptr< std::string > > columns_
Definition: ParserNode.h:1406
std::unique_ptr< std::string > table_
Definition: ParserNode.h:1405

Member Function Documentation

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

Implements Parser::DDLStmt.

Definition at line 5124 of file ParserNode.cpp.

References CHECK, Parser::check_alter_table_privilege(), Executor::clearExternalCaches(), ColumnDescriptor::columnId, ColumnDescriptor::columnName, columns_, ColumnDescriptor::columnType, Data_Namespace::DISK_LEVEL, legacylockmgr::ExecutorOuterLock, g_test_drop_column_rollback, SQLTypeInfo::get_physical_cols(), Catalog_Namespace::SessionInfo::getCatalog(), legacylockmgr::LockMgr< MutexType, KeyType >::getMutex(), TableDescriptor::hasDeletedCol, TableDescriptor::isView, TableDescriptor::nColumns, TableDescriptor::nShards, TableDescriptor::persistenceLevel, TableDescriptor::shardedColumnId, ddl_utils::TABLE, table_, table_is_temporary(), TableDescriptor::tableId, and ddl_utils::validate_table_type().

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

5125  {
5126  if (read_only_mode) {
5127  throw std::runtime_error("DROP COLUMN invalid in read only mode.");
5128  }
5129  // TODO: Review add and drop column implementation
5130  const auto execute_write_lock = heavyai::unique_lock<heavyai::shared_mutex>(
5133  auto& catalog = session.getCatalog();
5134  const auto td_with_lock =
5136  catalog, *table_, true);
5137  const auto td = td_with_lock();
5138  if (!td) {
5139  throw std::runtime_error("Table " + *table_ + " does not exist.");
5140  }
5142  if (td->isView) {
5143  throw std::runtime_error("Dropping a column from a view is not supported.");
5144  }
5145  if (table_is_temporary(td)) {
5146  throw std::runtime_error(
5147  "Dropping a column from a temporary table is not yet supported.");
5148  }
5149 
5150  check_alter_table_privilege(session, td);
5151 
5152  for (const auto& column : columns_) {
5153  if (nullptr == catalog.getMetadataForColumn(td->tableId, *column)) {
5154  throw std::runtime_error("Column " + *column + " does not exist.");
5155  }
5156  }
5157 
5158  if (td->nColumns <= (td->hasDeletedCol ? 3 : 2)) {
5159  throw std::runtime_error("Table " + *table_ + " has only one column.");
5160  }
5161 
5162  // invalidate cached item
5163  Executor::clearExternalCaches(false, td, catalog.getCurrentDB().dbId);
5164 
5165  catalog.getSqliteConnector().query("BEGIN TRANSACTION");
5166  try {
5167  std::vector<int> columnIds;
5168  for (const auto& column : columns_) {
5169  ColumnDescriptor cd = *catalog.getMetadataForColumn(td->tableId, *column);
5170  if (td->nShards > 0 && td->shardedColumnId == cd.columnId) {
5171  throw std::runtime_error("Dropping sharding column " + cd.columnName +
5172  " is not supported.");
5173  }
5174  catalog.dropColumn(*td, cd);
5175  columnIds.push_back(cd.columnId);
5176  for (int i = 0; i < cd.columnType.get_physical_cols(); i++) {
5177  const auto pcd = catalog.getMetadataForColumn(td->tableId, cd.columnId + i + 1);
5178  CHECK(pcd);
5179  catalog.dropColumn(*td, *pcd);
5180  columnIds.push_back(cd.columnId + i + 1);
5181  }
5182  }
5183 
5184  for (auto shard : catalog.getPhysicalTablesDescriptors(td)) {
5185  shard->fragmenter->dropColumns(columnIds);
5186  }
5187  // if test forces to rollback
5189  throw std::runtime_error("lol!");
5190  }
5191  catalog.roll(true);
5192  if (td->persistenceLevel == Data_Namespace::MemoryLevel::DISK_LEVEL) {
5193  catalog.resetTableEpochFloor(td->tableId);
5194  catalog.checkpoint(td->tableId);
5195  }
5196  catalog.getSqliteConnector().query("END TRANSACTION");
5197  } catch (...) {
5198  catalog.setForReload(td->tableId);
5199  catalog.roll(false);
5200  catalog.getSqliteConnector().query("ROLLBACK TRANSACTION");
5201  throw;
5202  }
5203 }
std::list< std::unique_ptr< std::string > > columns_
Definition: ParserNode.h:1406
int get_physical_cols() const
Definition: sqltypes.h:360
std::unique_lock< T > unique_lock
specifies the content in-memory of a row in the column metadata table
bool g_test_drop_column_rollback
Definition: ParserNode.cpp:77
void check_alter_table_privilege(const Catalog_Namespace::SessionInfo &session, const TableDescriptor *td)
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
void validate_table_type(const TableDescriptor *td, const TableType expected_table_type, const std::string &command)
Definition: DdlUtils.cpp:693
#define CHECK(condition)
Definition: Logger.h:222
static void clearExternalCaches(bool for_update, const TableDescriptor *td, const int current_db_id)
Definition: Execute.h:391
SQLTypeInfo columnType
std::string columnName
std::unique_ptr< std::string > table_
Definition: ParserNode.h:1405

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

const std::string* Parser::DropColumnStmt::get_table ( ) const
inline

Definition at line 1402 of file ParserNode.h.

References table_.

1402 { return table_.get(); }
std::unique_ptr< std::string > table_
Definition: ParserNode.h:1405

Member Data Documentation

std::list<std::unique_ptr<std::string> > Parser::DropColumnStmt::columns_
private

Definition at line 1406 of file ParserNode.h.

Referenced by DropColumnStmt(), and execute().

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

Definition at line 1405 of file ParserNode.h.

Referenced by execute(), and get_table().


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