OmniSciDB  0fdbebe030
 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 1311 of file ParserNode.h.

Constructor & Destructor Documentation

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

Definition at line 1313 of file ParserNode.h.

References columns.

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

Member Function Documentation

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

Implements Parser::DDLStmt.

Definition at line 3266 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(), and table_is_temporary().

3266  {
3267  auto& catalog = session.getCatalog();
3268 
3269  // TODO(adb): the catalog should be handling this locking.
3270  const auto execute_write_lock = mapd_unique_lock<mapd_shared_mutex>(
3273 
3274  const auto td_with_lock =
3276  catalog, *table, true);
3277  const auto td = td_with_lock();
3278  if (!td) {
3279  throw std::runtime_error("Table " + *table + " does not exist.");
3280  }
3281  if (td->isView) {
3282  throw std::runtime_error("Dropping a column from a view is not supported.");
3283  }
3284  if (table_is_temporary(td)) {
3285  throw std::runtime_error(
3286  "Dropping a column from a temporary table is not yet supported.");
3287  }
3288 
3289  check_alter_table_privilege(session, td);
3290 
3291  for (const auto& column : columns) {
3292  if (nullptr == catalog.getMetadataForColumn(td->tableId, *column)) {
3293  throw std::runtime_error("Column " + *column + " does not exist.");
3294  }
3295  }
3296 
3297  if (td->nColumns <= (td->hasDeletedCol ? 3 : 2)) {
3298  throw std::runtime_error("Table " + *table + " has only one column.");
3299  }
3300 
3301  catalog.getSqliteConnector().query("BEGIN TRANSACTION");
3302  try {
3303  std::vector<int> columnIds;
3304  for (const auto& column : columns) {
3305  ColumnDescriptor cd = *catalog.getMetadataForColumn(td->tableId, *column);
3306  if (td->nShards > 0 && td->shardedColumnId == cd.columnId) {
3307  throw std::runtime_error("Dropping sharding column " + cd.columnName +
3308  " is not supported.");
3309  }
3310  catalog.dropColumn(*td, cd);
3311  columnIds.push_back(cd.columnId);
3312  for (int i = 0; i < cd.columnType.get_physical_cols(); i++) {
3313  const auto pcd = catalog.getMetadataForColumn(td->tableId, cd.columnId + i + 1);
3314  CHECK(pcd);
3315  catalog.dropColumn(*td, *pcd);
3316  columnIds.push_back(cd.columnId + i + 1);
3317  }
3318  }
3319 
3320  for (auto shard : catalog.getPhysicalTablesDescriptors(td)) {
3321  shard->fragmenter->dropColumns(columnIds);
3322  }
3323  // if test forces to rollback
3325  throw std::runtime_error("lol!");
3326  }
3327  catalog.roll(true);
3328  if (td->persistenceLevel == Data_Namespace::MemoryLevel::DISK_LEVEL) {
3329  catalog.checkpoint(td->tableId);
3330  }
3331  catalog.getSqliteConnector().query("END TRANSACTION");
3332  } catch (...) {
3333  catalog.setForReload(td->tableId);
3334  catalog.roll(false);
3335  catalog.getSqliteConnector().query("ROLLBACK TRANSACTION");
3336  throw;
3337  }
3338 }
std::list< std::unique_ptr< std::string > > columns
Definition: ParserNode.h:1324
int get_physical_cols() const
Definition: sqltypes.h:269
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:69
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:76
std::unique_ptr< std::string > table
Definition: ParserNode.h:1323
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 1320 of file ParserNode.h.

References table.

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

Member Data Documentation

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

Definition at line 1324 of file ParserNode.h.

Referenced by DropColumnStmt().

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

Definition at line 1323 of file ParserNode.h.

Referenced by get_table().


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