OmniSciDB  dfae7c3b14
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) 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 1313 of file ParserNode.h.

Constructor & Destructor Documentation

◆ DropColumnStmt()

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

Definition at line 1315 of file ParserNode.h.

1315  : table(tab) {
1316  for (const auto col : *cols) {
1317  this->columns.emplace_back(col);
1318  }
1319  delete cols;
1320  }
std::list< std::unique_ptr< std::string > > columns
Definition: ParserNode.h:1326
std::unique_ptr< std::string > table
Definition: ParserNode.h:1325

Member Function Documentation

◆ execute()

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

Implements Parser::DDLStmt.

Definition at line 3448 of file ParserNode.cpp.

References CHECK, Parser::check_alter_table_privilege(), ColumnDescriptor::columnId, ColumnDescriptor::columnName, 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(), CacheInvalidator< CACHE_HOLDING_TYPES >::invalidateCaches(), and table_is_temporary().

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

3448  {
3449  auto& catalog = session.getCatalog();
3450 
3451  // TODO(adb): the catalog should be handling this locking.
3452  const auto execute_write_lock = mapd_unique_lock<mapd_shared_mutex>(
3455 
3456  const auto td_with_lock =
3458  catalog, *table, true);
3459  const auto td = td_with_lock();
3460  if (!td) {
3461  throw std::runtime_error("Table " + *table + " does not exist.");
3462  }
3463  if (td->isView) {
3464  throw std::runtime_error("Dropping a column from a view is not supported.");
3465  }
3466  if (table_is_temporary(td)) {
3467  throw std::runtime_error(
3468  "Dropping a column from a temporary table is not yet supported.");
3469  }
3470 
3471  check_alter_table_privilege(session, td);
3472 
3473  for (const auto& column : columns) {
3474  if (nullptr == catalog.getMetadataForColumn(td->tableId, *column)) {
3475  throw std::runtime_error("Column " + *column + " does not exist.");
3476  }
3477  }
3478 
3479  if (td->nColumns <= (td->hasDeletedCol ? 3 : 2)) {
3480  throw std::runtime_error("Table " + *table + " has only one column.");
3481  }
3482 
3483  catalog.getSqliteConnector().query("BEGIN TRANSACTION");
3484  try {
3485  std::vector<int> columnIds;
3486  for (const auto& column : columns) {
3487  ColumnDescriptor cd = *catalog.getMetadataForColumn(td->tableId, *column);
3488  if (td->nShards > 0 && td->shardedColumnId == cd.columnId) {
3489  throw std::runtime_error("Dropping sharding column " + cd.columnName +
3490  " is not supported.");
3491  }
3492  catalog.dropColumn(*td, cd);
3493  columnIds.push_back(cd.columnId);
3494  for (int i = 0; i < cd.columnType.get_physical_cols(); i++) {
3495  const auto pcd = catalog.getMetadataForColumn(td->tableId, cd.columnId + i + 1);
3496  CHECK(pcd);
3497  catalog.dropColumn(*td, *pcd);
3498  columnIds.push_back(cd.columnId + i + 1);
3499  }
3500  }
3501 
3502  for (auto shard : catalog.getPhysicalTablesDescriptors(td)) {
3503  shard->fragmenter->dropColumns(columnIds);
3504  }
3505  // if test forces to rollback
3507  throw std::runtime_error("lol!");
3508  }
3509  catalog.roll(true);
3510  if (td->persistenceLevel == Data_Namespace::MemoryLevel::DISK_LEVEL) {
3511  catalog.checkpoint(td->tableId);
3512  }
3513  catalog.getSqliteConnector().query("END TRANSACTION");
3514  } catch (...) {
3515  catalog.setForReload(td->tableId);
3516  catalog.roll(false);
3517  catalog.getSqliteConnector().query("ROLLBACK TRANSACTION");
3518  throw;
3519  }
3520 
3521  // invalidate cached hashtable
3523 }
static void invalidateCaches()
std::list< std::unique_ptr< std::string > > columns
Definition: ParserNode.h:1326
Catalog & getCatalog() const
Definition: SessionInfo.h:65
int get_physical_cols() const
Definition: sqltypes.h:280
specifies the content in-memory of a row in the column metadata table
bool g_test_drop_column_rollback
Definition: ParserNode.cpp:69
void check_alter_table_privilege(const Catalog_Namespace::SessionInfo &session, const TableDescriptor *td)
bool table_is_temporary(const TableDescriptor *const td)
std::unique_ptr< std::string > table
Definition: ParserNode.h:1325
static std::shared_ptr< MutexType > getMutex(const LockType lockType, const KeyType &key)
Definition: LegacyLockMgr.h:51
#define CHECK(condition)
Definition: Logger.h:197
SQLTypeInfo columnType
std::string columnName
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_table()

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

Definition at line 1322 of file ParserNode.h.

1322 { return table.get(); }
std::unique_ptr< std::string > table
Definition: ParserNode.h:1325

Member Data Documentation

◆ columns

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

◆ table

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

Definition at line 1325 of file ParserNode.h.


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