OmniSciDB  eb3a3d0a03
 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) 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 1362 of file ParserNode.h.

Constructor & Destructor Documentation

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

Definition at line 1364 of file ParserNode.h.

References columns_.

1364  : table_(tab) {
1365  for (const auto col : *cols) {
1366  this->columns_.emplace_back(col);
1367  }
1368  delete cols;
1369  }
std::list< std::unique_ptr< std::string > > columns_
Definition: ParserNode.h:1375
std::unique_ptr< std::string > table_
Definition: ParserNode.h:1374

Member Function Documentation

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

Implements Parser::DDLStmt.

Definition at line 4435 of file ParserNode.cpp.

References CHECK, Parser::check_alter_table_privilege(), 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, i, CacheInvalidator< CACHE_HOLDING_TYPES >::invalidateCaches(), 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 omnisci.cursor.Cursor::executemany().

4435  {
4436  auto& catalog = session.getCatalog();
4437 
4438  // TODO(adb): the catalog should be handling this locking.
4439  const auto execute_write_lock = mapd_unique_lock<mapd_shared_mutex>(
4442 
4443  const auto td_with_lock =
4445  catalog, *table_, true);
4446  const auto td = td_with_lock();
4447  if (!td) {
4448  throw std::runtime_error("Table " + *table_ + " does not exist.");
4449  }
4451  if (td->isView) {
4452  throw std::runtime_error("Dropping a column from a view is not supported.");
4453  }
4454  if (table_is_temporary(td)) {
4455  throw std::runtime_error(
4456  "Dropping a column from a temporary table is not yet supported.");
4457  }
4458 
4459  check_alter_table_privilege(session, td);
4460 
4461  for (const auto& column : columns_) {
4462  if (nullptr == catalog.getMetadataForColumn(td->tableId, *column)) {
4463  throw std::runtime_error("Column " + *column + " does not exist.");
4464  }
4465  }
4466 
4467  if (td->nColumns <= (td->hasDeletedCol ? 3 : 2)) {
4468  throw std::runtime_error("Table " + *table_ + " has only one column.");
4469  }
4470 
4471  catalog.getSqliteConnector().query("BEGIN TRANSACTION");
4472  try {
4473  std::vector<int> columnIds;
4474  for (const auto& column : columns_) {
4475  ColumnDescriptor cd = *catalog.getMetadataForColumn(td->tableId, *column);
4476  if (td->nShards > 0 && td->shardedColumnId == cd.columnId) {
4477  throw std::runtime_error("Dropping sharding column " + cd.columnName +
4478  " is not supported.");
4479  }
4480  catalog.dropColumn(*td, cd);
4481  columnIds.push_back(cd.columnId);
4482  for (int i = 0; i < cd.columnType.get_physical_cols(); i++) {
4483  const auto pcd = catalog.getMetadataForColumn(td->tableId, cd.columnId + i + 1);
4484  CHECK(pcd);
4485  catalog.dropColumn(*td, *pcd);
4486  columnIds.push_back(cd.columnId + i + 1);
4487  }
4488  }
4489 
4490  for (auto shard : catalog.getPhysicalTablesDescriptors(td)) {
4491  shard->fragmenter->dropColumns(columnIds);
4492  }
4493  // if test forces to rollback
4495  throw std::runtime_error("lol!");
4496  }
4497  catalog.roll(true);
4498  if (td->persistenceLevel == Data_Namespace::MemoryLevel::DISK_LEVEL) {
4499  catalog.checkpoint(td->tableId);
4500  }
4501  catalog.getSqliteConnector().query("END TRANSACTION");
4502  } catch (...) {
4503  catalog.setForReload(td->tableId);
4504  catalog.roll(false);
4505  catalog.getSqliteConnector().query("ROLLBACK TRANSACTION");
4506  throw;
4507  }
4508 
4509  // invalidate cached hashtable
4511 }
static void invalidateCaches()
std::list< std::unique_ptr< std::string > > columns_
Definition: ParserNode.h:1375
int get_physical_cols() const
Definition: sqltypes.h:350
specifies the content in-memory of a row in the column metadata table
bool g_test_drop_column_rollback
Definition: ParserNode.cpp:78
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
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:650
#define CHECK(condition)
Definition: Logger.h:209
SQLTypeInfo columnType
std::string columnName
std::unique_ptr< std::string > table_
Definition: ParserNode.h:1374

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

References table_.

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

Member Data Documentation

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

Definition at line 1375 of file ParserNode.h.

Referenced by DropColumnStmt(), and execute().

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

Definition at line 1374 of file ParserNode.h.

Referenced by execute(), and get_table().


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