OmniSciDB  ba1bac9284
 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 1357 of file ParserNode.h.

Constructor & Destructor Documentation

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

Definition at line 1359 of file ParserNode.h.

References columns.

1359  : table(tab) {
1360  for (const auto col : *cols) {
1361  this->columns.emplace_back(col);
1362  }
1363  delete cols;
1364  }
std::list< std::unique_ptr< std::string > > columns
Definition: ParserNode.h:1370
std::unique_ptr< std::string > table
Definition: ParserNode.h:1369

Member Function Documentation

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

Implements Parser::DDLStmt.

Definition at line 4274 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(), TableDescriptor::hasDeletedCol, i, CacheInvalidator< CACHE_HOLDING_TYPES >::invalidateCaches(), TableDescriptor::isView, TableDescriptor::nColumns, TableDescriptor::nShards, TableDescriptor::persistenceLevel, TableDescriptor::shardedColumnId, test_readcsv::table, ddl_utils::TABLE, table_is_temporary(), TableDescriptor::tableId, and ddl_utils::validate_table_type().

Referenced by Parser::AlterTableStmt::delegateExecute(), and omnisci.cursor.Cursor::executemany().

4274  {
4275  auto& catalog = session.getCatalog();
4276 
4277  // TODO(adb): the catalog should be handling this locking.
4278  const auto execute_write_lock = mapd_unique_lock<mapd_shared_mutex>(
4281 
4282  const auto td_with_lock =
4284  catalog, *table, true);
4285  const auto td = td_with_lock();
4286  if (!td) {
4287  throw std::runtime_error("Table " + *table + " does not exist.");
4288  }
4290  if (td->isView) {
4291  throw std::runtime_error("Dropping a column from a view is not supported.");
4292  }
4293  if (table_is_temporary(td)) {
4294  throw std::runtime_error(
4295  "Dropping a column from a temporary table is not yet supported.");
4296  }
4297 
4298  check_alter_table_privilege(session, td);
4299 
4300  for (const auto& column : columns) {
4301  if (nullptr == catalog.getMetadataForColumn(td->tableId, *column)) {
4302  throw std::runtime_error("Column " + *column + " does not exist.");
4303  }
4304  }
4305 
4306  if (td->nColumns <= (td->hasDeletedCol ? 3 : 2)) {
4307  throw std::runtime_error("Table " + *table + " has only one column.");
4308  }
4309 
4310  catalog.getSqliteConnector().query("BEGIN TRANSACTION");
4311  try {
4312  std::vector<int> columnIds;
4313  for (const auto& column : columns) {
4314  ColumnDescriptor cd = *catalog.getMetadataForColumn(td->tableId, *column);
4315  if (td->nShards > 0 && td->shardedColumnId == cd.columnId) {
4316  throw std::runtime_error("Dropping sharding column " + cd.columnName +
4317  " is not supported.");
4318  }
4319  catalog.dropColumn(*td, cd);
4320  columnIds.push_back(cd.columnId);
4321  for (int i = 0; i < cd.columnType.get_physical_cols(); i++) {
4322  const auto pcd = catalog.getMetadataForColumn(td->tableId, cd.columnId + i + 1);
4323  CHECK(pcd);
4324  catalog.dropColumn(*td, *pcd);
4325  columnIds.push_back(cd.columnId + i + 1);
4326  }
4327  }
4328 
4329  for (auto shard : catalog.getPhysicalTablesDescriptors(td)) {
4330  shard->fragmenter->dropColumns(columnIds);
4331  }
4332  // if test forces to rollback
4334  throw std::runtime_error("lol!");
4335  }
4336  catalog.roll(true);
4337  if (td->persistenceLevel == Data_Namespace::MemoryLevel::DISK_LEVEL) {
4338  catalog.checkpoint(td->tableId);
4339  }
4340  catalog.getSqliteConnector().query("END TRANSACTION");
4341  } catch (...) {
4342  catalog.setForReload(td->tableId);
4343  catalog.roll(false);
4344  catalog.getSqliteConnector().query("ROLLBACK TRANSACTION");
4345  throw;
4346  }
4347 
4348  // invalidate cached hashtable
4350 }
static void invalidateCaches()
std::list< std::unique_ptr< std::string > > columns
Definition: ParserNode.h:1370
int get_physical_cols() const
Definition: sqltypes.h:335
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:67
std::unique_ptr< std::string > table
Definition: ParserNode.h:1369
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:554
#define CHECK(condition)
Definition: Logger.h:206
SQLTypeInfo columnType
std::string columnName

+ 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 1366 of file ParserNode.h.

References table.

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

Member Data Documentation

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

Definition at line 1369 of file ParserNode.h.

Referenced by get_table().


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