OmniSciDB  06b3bd477c
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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) 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

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

Definition at line 1315 of file ParserNode.h.

References columns.

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

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

Implements Parser::DDLStmt.

Definition at line 3460 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().

3460  {
3461  auto& catalog = session.getCatalog();
3462 
3463  // TODO(adb): the catalog should be handling this locking.
3464  const auto execute_write_lock = mapd_unique_lock<mapd_shared_mutex>(
3467 
3468  const auto td_with_lock =
3470  catalog, *table, true);
3471  const auto td = td_with_lock();
3472  if (!td) {
3473  throw std::runtime_error("Table " + *table + " does not exist.");
3474  }
3475  if (td->isView) {
3476  throw std::runtime_error("Dropping a column from a view is not supported.");
3477  }
3478  if (table_is_temporary(td)) {
3479  throw std::runtime_error(
3480  "Dropping a column from a temporary table is not yet supported.");
3481  }
3482 
3483  check_alter_table_privilege(session, td);
3484 
3485  for (const auto& column : columns) {
3486  if (nullptr == catalog.getMetadataForColumn(td->tableId, *column)) {
3487  throw std::runtime_error("Column " + *column + " does not exist.");
3488  }
3489  }
3490 
3491  if (td->nColumns <= (td->hasDeletedCol ? 3 : 2)) {
3492  throw std::runtime_error("Table " + *table + " has only one column.");
3493  }
3494 
3495  catalog.getSqliteConnector().query("BEGIN TRANSACTION");
3496  try {
3497  std::vector<int> columnIds;
3498  for (const auto& column : columns) {
3499  ColumnDescriptor cd = *catalog.getMetadataForColumn(td->tableId, *column);
3500  if (td->nShards > 0 && td->shardedColumnId == cd.columnId) {
3501  throw std::runtime_error("Dropping sharding column " + cd.columnName +
3502  " is not supported.");
3503  }
3504  catalog.dropColumn(*td, cd);
3505  columnIds.push_back(cd.columnId);
3506  for (int i = 0; i < cd.columnType.get_physical_cols(); i++) {
3507  const auto pcd = catalog.getMetadataForColumn(td->tableId, cd.columnId + i + 1);
3508  CHECK(pcd);
3509  catalog.dropColumn(*td, *pcd);
3510  columnIds.push_back(cd.columnId + i + 1);
3511  }
3512  }
3513 
3514  for (auto shard : catalog.getPhysicalTablesDescriptors(td)) {
3515  shard->fragmenter->dropColumns(columnIds);
3516  }
3517  // if test forces to rollback
3519  throw std::runtime_error("lol!");
3520  }
3521  catalog.roll(true);
3522  if (td->persistenceLevel == Data_Namespace::MemoryLevel::DISK_LEVEL) {
3523  catalog.checkpoint(td->tableId);
3524  }
3525  catalog.getSqliteConnector().query("END TRANSACTION");
3526  } catch (...) {
3527  catalog.setForReload(td->tableId);
3528  catalog.roll(false);
3529  catalog.getSqliteConnector().query("ROLLBACK TRANSACTION");
3530  throw;
3531  }
3532 
3533  // invalidate cached hashtable
3535 }
static void invalidateCaches()
std::list< std::unique_ptr< std::string > > columns
Definition: ParserNode.h:1326
int get_physical_cols() const
Definition: sqltypes.h:279
CHECK(cgen_state)
specifies the content in-memory of a row in the column metadata table
bool g_test_drop_column_rollback
Definition: ParserNode.cpp:71
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
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
SQLTypeInfo columnType
std::string columnName

+ Here is the call graph for this function:

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

Definition at line 1322 of file ParserNode.h.

References table.

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

Member Data Documentation

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

Definition at line 1326 of file ParserNode.h.

Referenced by DropColumnStmt().

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

Definition at line 1325 of file ParserNode.h.

Referenced by get_table().


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