OmniSciDB  04ee39c94c
Parser::CreateTableStmt Class Reference

#include <ParserNode.h>

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

Public Member Functions

 CreateTableStmt (std::string *tab, std::list< TableElement *> *table_elems, bool is_temporary, bool if_not_exists, std::list< NameValueAssign *> *s)
 
const std::string * get_table () const
 
const std::list< std::unique_ptr< TableElement > > & get_table_element_list () const
 
void execute (const Catalog_Namespace::SessionInfo &session) override
 
- 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 953 of file ParserNode.h.

Constructor & Destructor Documentation

◆ CreateTableStmt()

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

Definition at line 955 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:982
std::list< std::unique_ptr< NameValueAssign > > storage_options_
Definition: ParserNode.h:985
#define CHECK(condition)
Definition: Logger.h:187
std::unique_ptr< std::string > table_
Definition: ParserNode.h:981

Member Function Documentation

◆ execute()

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

Implements Parser::DDLStmt.

Definition at line 2130 of file ParserNode.cpp.

References Catalog_Namespace::SessionInfo::checkDBAccessPrivileges(), ColumnDescriptor::columnName, Data_Namespace::CPU_LEVEL, AccessPrivileges::CREATE_TABLE, DEFAULT_FRAGMENT_ROWS, DEFAULT_MAX_CHUNK_SIZE, DEFAULT_MAX_ROWS, DEFAULT_PAGE_SIZE, Data_Namespace::DISK_LEVEL, TableDescriptor::fragmenter, TableDescriptor::fragPageSize, TableDescriptor::fragType, Parser::ColumnDef::get_column_name(), Catalog_Namespace::SessionInfo::get_currentUser(), Parser::anonymous_namespace{ParserNode.cpp}::get_table_definitions(), Catalog_Namespace::SessionInfo::getCatalog(), Fragmenter_Namespace::INSERT_ORDER, TableDescriptor::isView, TableDescriptor::keyMetainfo, TableDescriptor::maxChunkSize, TableDescriptor::maxFragRows, TableDescriptor::maxRows, TableDescriptor::nColumns, TableDescriptor::nShards, TableDescriptor::persistenceLevel, reserved_keywords, Parser::anonymous_namespace{ParserNode.cpp}::serialize_key_metainfo(), Parser::anonymous_namespace{ParserNode.cpp}::shard_column_index(), TableDescriptor::shardedColumnId, TableDBObjectType, TableDescriptor::tableName, TableDescriptor::userId, Catalog_Namespace::UserMetadata::userId, and validate_shared_dictionary().

2130  {
2131  auto& catalog = session.getCatalog();
2132  // check access privileges
2135  throw std::runtime_error("Table " + *table_ +
2136  " will not be created. User has no create privileges.");
2137  }
2138 
2139  if (catalog.getMetadataForTable(*table_) != nullptr) {
2140  if (if_not_exists_) {
2141  return;
2142  }
2143  throw std::runtime_error("Table " + *table_ + " already exists.");
2144  }
2145  std::list<ColumnDescriptor> columns;
2146  std::unordered_set<std::string> uc_col_names;
2147  std::vector<SharedDictionaryDef> shared_dict_defs;
2148  const ShardKeyDef* shard_key_def{nullptr};
2149  for (auto& e : table_element_list_) {
2150  if (dynamic_cast<SharedDictionaryDef*>(e.get())) {
2151  auto shared_dict_def = static_cast<SharedDictionaryDef*>(e.get());
2153  this, shared_dict_def, columns, shared_dict_defs, catalog);
2154  shared_dict_defs.push_back(*shared_dict_def);
2155  continue;
2156  }
2157  if (dynamic_cast<ShardKeyDef*>(e.get())) {
2158  if (shard_key_def) {
2159  throw std::runtime_error("Specified more than one shard key");
2160  }
2161  shard_key_def = static_cast<const ShardKeyDef*>(e.get());
2162  continue;
2163  }
2164  if (!dynamic_cast<ColumnDef*>(e.get())) {
2165  throw std::runtime_error("Table constraints are not supported yet.");
2166  }
2167  ColumnDef* coldef = static_cast<ColumnDef*>(e.get());
2168  ColumnDescriptor cd;
2169  cd.columnName = *coldef->get_column_name();
2170  const auto uc_col_name = boost::to_upper_copy<std::string>(cd.columnName);
2171  if (reserved_keywords.find(uc_col_name) != reserved_keywords.end()) {
2172  throw std::runtime_error("Cannot create column with reserved keyword '" +
2173  cd.columnName + "'");
2174  }
2175  const auto it_ok = uc_col_names.insert(uc_col_name);
2176  if (!it_ok.second) {
2177  throw std::runtime_error("Column '" + cd.columnName + "' defined more than once");
2178  }
2179 
2180  setColumnDescriptor(cd, coldef);
2181  columns.push_back(cd);
2182  }
2183 
2184  TableDescriptor td;
2185  td.tableName = *table_;
2186  td.userId = session.get_currentUser().userId;
2187  td.nColumns = columns.size();
2188  td.isView = false;
2189  td.fragmenter = nullptr;
2195  if (shard_key_def) {
2196  td.shardedColumnId = shard_column_index(shard_key_def->get_column(), columns);
2197  if (!td.shardedColumnId) {
2198  throw std::runtime_error("Specified shard column " + shard_key_def->get_column() +
2199  " doesn't exist");
2200  }
2201  }
2202  if (is_temporary_) {
2204  } else {
2206  }
2207  if (!storage_options_.empty()) {
2208  for (auto& p : storage_options_) {
2209  get_table_definitions(td, p, columns);
2210  }
2211  }
2212  if (td.shardedColumnId && !td.nShards) {
2213  throw std::runtime_error("SHARD_COUNT needs to be specified with SHARD_KEY.");
2214  }
2215  td.keyMetainfo = serialize_key_metainfo(shard_key_def, shared_dict_defs);
2216  catalog.createShardedTable(td, columns, shared_dict_defs);
2217  // TODO (max): It's transactionally unsafe, should be fixed: we may create object w/o
2218  // privileges
2219  SysCatalog::instance().createDBObject(
2220  session.get_currentUser(), td.tableName, TableDBObjectType, catalog);
2221 }
static std::set< std::string > reserved_keywords
size_t shard_column_index(const std::string &name, const std::list< ColumnDescriptor > &columns)
void setColumnDescriptor(ColumnDescriptor &cd, const ColumnDef *coldef)
std::string tableName
std::list< std::unique_ptr< TableElement > > table_element_list_
Definition: ParserNode.h:982
#define DEFAULT_MAX_ROWS
const UserMetadata & get_currentUser() const
Definition: SessionInfo.h:93
Catalog & getCatalog() const
Definition: SessionInfo.h:90
#define DEFAULT_PAGE_SIZE
specifies the content in-memory of a row in the column metadata table
static const AccessPrivileges CREATE_TABLE
Definition: DBObject.h:151
std::string keyMetainfo
Fragmenter_Namespace::FragmenterType fragType
Data_Namespace::MemoryLevel persistenceLevel
std::list< std::unique_ptr< NameValueAssign > > storage_options_
Definition: ParserNode.h:985
bool checkDBAccessPrivileges(const DBObjectType &permissionType, const AccessPrivileges &privs, const std::string &objectName="") const
Definition: SessionInfo.cpp:24
#define DEFAULT_FRAGMENT_ROWS
void get_table_definitions(TableDescriptor &td, const std::unique_ptr< NameValueAssign > &p, const std::list< ColumnDescriptor > &columns)
#define DEFAULT_MAX_CHUNK_SIZE
specifies the content in-memory of a row in the table metadata table
Fragmenter_Namespace::AbstractFragmenter * fragmenter
std::string columnName
std::unique_ptr< std::string > table_
Definition: ParserNode.h:981
std::string serialize_key_metainfo(const ShardKeyDef *shard_key_def, const std::vector< SharedDictionaryDef > &shared_dict_defs)
void validate_shared_dictionary(const Parser::CreateTableStmt *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)
+ Here is the call graph for this function:

◆ get_table()

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

Definition at line 973 of file ParserNode.h.

Referenced by validate_shared_dictionary(), and validate_shared_dictionary_order().

973 { return table_.get(); }
std::unique_ptr< std::string > table_
Definition: ParserNode.h:981
+ Here is the caller graph for this function:

◆ get_table_element_list()

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

Definition at line 974 of file ParserNode.h.

References session.

Referenced by validate_shared_dictionary().

974  {
975  return table_element_list_;
976  }
std::list< std::unique_ptr< TableElement > > table_element_list_
Definition: ParserNode.h:982
+ Here is the caller graph for this function:

Member Data Documentation

◆ if_not_exists_

bool Parser::CreateTableStmt::if_not_exists_
private

Definition at line 984 of file ParserNode.h.

◆ is_temporary_

bool Parser::CreateTableStmt::is_temporary_
private

Definition at line 983 of file ParserNode.h.

◆ storage_options_

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

Definition at line 985 of file ParserNode.h.

◆ table_

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

Definition at line 981 of file ParserNode.h.

◆ table_element_list_

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

Definition at line 982 of file ParserNode.h.


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