OmniSciDB  f632821e96
Parser::CreateTableStmt Class Reference

#include <ParserNode.h>

+ Inheritance diagram for Parser::CreateTableStmt:
+ Collaboration diagram for Parser::CreateTableStmt:

Public Member Functions

 CreateTableStmt (std::string *tab, const std::string *storage, std::list< TableElement *> *table_elems, bool is_temporary, bool if_not_exists, std::list< NameValueAssign *> *s)
 
const std::string * get_table () const override
 
const std::list< std::unique_ptr< TableElement > > & get_table_element_list () const override
 
void execute (const Catalog_Namespace::SessionInfo &session) override
 
void executeDryRun (const Catalog_Namespace::SessionInfo &session, TableDescriptor &td, std::list< ColumnDescriptor > &columns, std::vector< SharedDictionaryDef > &shared_dict_defs)
 
- 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< TableElement > > table_element_list_
 
bool is_temporary_
 
bool if_not_exists_
 
std::list< std::unique_ptr< NameValueAssign > > storage_options_
 

Detailed Description

Definition at line 952 of file ParserNode.h.

Constructor & Destructor Documentation

◆ CreateTableStmt()

Parser::CreateTableStmt::CreateTableStmt ( std::string *  tab,
const std::string *  storage,
std::list< TableElement *> *  table_elems,
bool  is_temporary,
bool  if_not_exists,
std::list< NameValueAssign *> *  s 
)
inline

Definition at line 954 of file ParserNode.h.

References CHECK.

960  : table_(tab), is_temporary_(is_temporary), if_not_exists_(if_not_exists) {
961  CHECK(table_elems);
962  for (const auto e : *table_elems) {
963  table_element_list_.emplace_back(e);
964  }
965  delete table_elems;
966  if (s) {
967  for (const auto e : *s) {
968  storage_options_.emplace_back(e);
969  }
970  delete s;
971  }
972  }
std::list< std::unique_ptr< TableElement > > table_element_list_
Definition: ParserNode.h:987
std::list< std::unique_ptr< NameValueAssign > > storage_options_
Definition: ParserNode.h:990
#define CHECK(condition)
Definition: Logger.h:197
std::unique_ptr< std::string > table_
Definition: ParserNode.h:986

Member Function Documentation

◆ execute()

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

Implements Parser::DDLStmt.

Definition at line 2243 of file ParserNode.cpp.

References Catalog_Namespace::SessionInfo::checkDBAccessPrivileges(), AccessPrivileges::CREATE_TABLE, legacylockmgr::ExecutorOuterLock, Catalog_Namespace::SessionInfo::get_currentUser(), Catalog_Namespace::SessionInfo::getCatalog(), legacylockmgr::LockMgr< MutexType, KeyType >::getMutex(), TableDBObjectType, TableDescriptor::tableName, TableDescriptor::userId, and Catalog_Namespace::UserMetadata::userId.

2243  {
2244  auto& catalog = session.getCatalog();
2245 
2246  const auto execute_write_lock = mapd_unique_lock<mapd_shared_mutex>(
2249 
2250  // check access privileges
2253  throw std::runtime_error("Table " + *table_ +
2254  " will not be created. User has no create privileges.");
2255  }
2256 
2257  if (!catalog.validateNonExistentTableOrView(*table_, if_not_exists_)) {
2258  return;
2259  }
2260 
2261  TableDescriptor td;
2262  std::list<ColumnDescriptor> columns;
2263  std::vector<SharedDictionaryDef> shared_dict_defs;
2264 
2265  executeDryRun(session, td, columns, shared_dict_defs);
2266  td.userId = session.get_currentUser().userId;
2267 
2268  catalog.createShardedTable(td, columns, shared_dict_defs);
2269  // TODO (max): It's transactionally unsafe, should be fixed: we may create object w/o
2270  // privileges
2271  SysCatalog::instance().createDBObject(
2272  session.get_currentUser(), td.tableName, TableDBObjectType, catalog);
2273 }
std::string tableName
void executeDryRun(const Catalog_Namespace::SessionInfo &session, TableDescriptor &td, std::list< ColumnDescriptor > &columns, std::vector< SharedDictionaryDef > &shared_dict_defs)
const UserMetadata & get_currentUser() const
Definition: SessionInfo.h:68
Catalog & getCatalog() const
Definition: SessionInfo.h:65
static const AccessPrivileges CREATE_TABLE
Definition: DBObject.h:159
bool checkDBAccessPrivileges(const DBObjectType &permissionType, const AccessPrivileges &privs, const std::string &objectName="") const
Definition: SessionInfo.cpp:24
static std::shared_ptr< MutexType > getMutex(const LockType lockType, const KeyType &key)
Definition: LegacyLockMgr.h:51
specifies the content in-memory of a row in the table metadata table
std::unique_ptr< std::string > table_
Definition: ParserNode.h:986
+ Here is the call graph for this function:

◆ executeDryRun()

void Parser::CreateTableStmt::executeDryRun ( const Catalog_Namespace::SessionInfo session,
TableDescriptor td,
std::list< ColumnDescriptor > &  columns,
std::vector< SharedDictionaryDef > &  shared_dict_defs 
)

Definition at line 2185 of file ParserNode.cpp.

References ColumnDescriptor::columnName, Data_Namespace::CPU_LEVEL, Data_Namespace::DISK_LEVEL, Parser::ColumnDef::get_column_name(), Parser::anonymous_namespace{ParserNode.cpp}::get_table_definitions(), Catalog_Namespace::SessionInfo::getCatalog(), TableDescriptor::keyMetainfo, TableDescriptor::nShards, TableDescriptor::persistenceLevel, Parser::anonymous_namespace{ParserNode.cpp}::serialize_key_metainfo(), ddl_utils::set_default_table_attributes(), Parser::anonymous_namespace{ParserNode.cpp}::shard_column_index(), TableDescriptor::shardedColumnId, ddl_utils::validate_non_duplicate_column(), and validate_shared_dictionary().

2188  {
2189  std::unordered_set<std::string> uc_col_names;
2190  const auto& catalog = session.getCatalog();
2191  const ShardKeyDef* shard_key_def{nullptr};
2192  for (auto& e : table_element_list_) {
2193  if (dynamic_cast<SharedDictionaryDef*>(e.get())) {
2194  auto shared_dict_def = static_cast<SharedDictionaryDef*>(e.get());
2196  this, shared_dict_def, columns, shared_dict_defs, catalog);
2197  shared_dict_defs.push_back(*shared_dict_def);
2198  continue;
2199  }
2200  if (dynamic_cast<ShardKeyDef*>(e.get())) {
2201  if (shard_key_def) {
2202  throw std::runtime_error("Specified more than one shard key");
2203  }
2204  shard_key_def = static_cast<const ShardKeyDef*>(e.get());
2205  continue;
2206  }
2207  if (!dynamic_cast<ColumnDef*>(e.get())) {
2208  throw std::runtime_error("Table constraints are not supported yet.");
2209  }
2210  ColumnDef* coldef = static_cast<ColumnDef*>(e.get());
2211  ColumnDescriptor cd;
2212  cd.columnName = *coldef->get_column_name();
2214  setColumnDescriptor(cd, coldef);
2215  columns.push_back(cd);
2216  }
2217 
2218  ddl_utils::set_default_table_attributes(*table_, td, columns.size());
2219 
2220  if (shard_key_def) {
2221  td.shardedColumnId = shard_column_index(shard_key_def->get_column(), columns);
2222  if (!td.shardedColumnId) {
2223  throw std::runtime_error("Specified shard column " + shard_key_def->get_column() +
2224  " doesn't exist");
2225  }
2226  }
2227  if (is_temporary_) {
2229  } else {
2231  }
2232  if (!storage_options_.empty()) {
2233  for (auto& p : storage_options_) {
2234  get_table_definitions(td, p, columns);
2235  }
2236  }
2237  if (td.shardedColumnId && !td.nShards) {
2238  throw std::runtime_error("SHARD_COUNT needs to be specified with SHARD_KEY.");
2239  }
2240  td.keyMetainfo = serialize_key_metainfo(shard_key_def, shared_dict_defs);
2241 }
size_t shard_column_index(const std::string &name, const std::list< ColumnDescriptor > &columns)
void setColumnDescriptor(ColumnDescriptor &cd, const ColumnDef *coldef)
std::list< std::unique_ptr< TableElement > > table_element_list_
Definition: ParserNode.h:987
void validate_non_duplicate_column(const std::string &column_name, std::unordered_set< std::string > &upper_column_names)
Definition: DdlUtils.cpp:520
Catalog & getCatalog() const
Definition: SessionInfo.h:65
specifies the content in-memory of a row in the column metadata table
std::string keyMetainfo
void set_default_table_attributes(const std::string &table_name, TableDescriptor &td, const int32_t column_count)
Definition: DdlUtils.cpp:506
Data_Namespace::MemoryLevel persistenceLevel
std::list< std::unique_ptr< NameValueAssign > > storage_options_
Definition: ParserNode.h:990
void validate_shared_dictionary(const Parser::CreateTableBaseStmt *stmt, const Parser::SharedDictionaryDef *shared_dict_def, const std::list< ColumnDescriptor > &columns, const std::vector< Parser::SharedDictionaryDef > &shared_dict_defs_so_far, const Catalog_Namespace::Catalog &catalog)
void get_table_definitions(TableDescriptor &td, const std::unique_ptr< NameValueAssign > &p, const std::list< ColumnDescriptor > &columns)
std::string columnName
std::unique_ptr< std::string > table_
Definition: ParserNode.h:986
std::string serialize_key_metainfo(const ShardKeyDef *shard_key_def, const std::vector< SharedDictionaryDef > &shared_dict_defs)
+ Here is the call graph for this function:

◆ get_table()

const std::string* Parser::CreateTableStmt::get_table ( ) const
inlineoverridevirtual

Implements Parser::CreateTableBaseStmt.

Definition at line 973 of file ParserNode.h.

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

◆ get_table_element_list()

const std::list<std::unique_ptr<TableElement> >& Parser::CreateTableStmt::get_table_element_list ( ) const
inlineoverridevirtual

Implements Parser::CreateTableBaseStmt.

Definition at line 974 of file ParserNode.h.

975  {
976  return table_element_list_;
977  }
std::list< std::unique_ptr< TableElement > > table_element_list_
Definition: ParserNode.h:987

Member Data Documentation

◆ if_not_exists_

bool Parser::CreateTableStmt::if_not_exists_
private

Definition at line 989 of file ParserNode.h.

◆ is_temporary_

bool Parser::CreateTableStmt::is_temporary_
private

Definition at line 988 of file ParserNode.h.

◆ storage_options_

std::list<std::unique_ptr<NameValueAssign> > Parser::CreateTableStmt::storage_options_
private

Definition at line 990 of file ParserNode.h.

◆ table_

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

Definition at line 986 of file ParserNode.h.

◆ table_element_list_

std::list<std::unique_ptr<TableElement> > Parser::CreateTableStmt::table_element_list_
private

Definition at line 987 of file ParserNode.h.


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