OmniSciDB  b24e664e58
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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
 
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 964 of file ParserNode.h.

Constructor & Destructor Documentation

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

References CHECK(), storage_options_, and table_element_list_.

971  : table_(tab), is_temporary_(is_temporary), if_not_exists_(if_not_exists) {
972  CHECK(table_elems);
973  for (const auto e : *table_elems) {
974  table_element_list_.emplace_back(e);
975  }
976  delete table_elems;
977  if (s) {
978  for (const auto e : *s) {
979  storage_options_.emplace_back(e);
980  }
981  delete s;
982  }
983  }
std::list< std::unique_ptr< TableElement > > table_element_list_
Definition: ParserNode.h:997
CHECK(cgen_state)
std::list< std::unique_ptr< NameValueAssign > > storage_options_
Definition: ParserNode.h:1000
std::unique_ptr< std::string > table_
Definition: ParserNode.h:996

+ Here is the call graph for this function:

Member Function Documentation

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

Implements Parser::DDLStmt.

Definition at line 2219 of file ParserNode.cpp.

References Catalog_Namespace::SessionInfo::checkDBAccessPrivileges(), AccessPrivileges::CREATE_TABLE, Catalog_Namespace::SessionInfo::get_currentUser(), Catalog_Namespace::SessionInfo::getCatalog(), TableDBObjectType, TableDescriptor::tableName, TableDescriptor::userId, and Catalog_Namespace::UserMetadata::userId.

2219  {
2220  auto& catalog = session.getCatalog();
2221  // check access privileges
2224  throw std::runtime_error("Table " + *table_ +
2225  " will not be created. User has no create privileges.");
2226  }
2227 
2228  if (catalog.getMetadataForTable(*table_) != nullptr) {
2229  if (if_not_exists_) {
2230  return;
2231  }
2232  throw std::runtime_error("Table " + *table_ + " already exists.");
2233  }
2234  TableDescriptor td;
2235  std::list<ColumnDescriptor> columns;
2236  std::unordered_set<std::string> uc_col_names;
2237  std::vector<SharedDictionaryDef> shared_dict_defs;
2238 
2239  executeDryRun(session, td, columns, shared_dict_defs);
2240  td.userId = session.get_currentUser().userId;
2241 
2242  catalog.createShardedTable(td, columns, shared_dict_defs);
2243  // TODO (max): It's transactionally unsafe, should be fixed: we may create object w/o
2244  // privileges
2245  SysCatalog::instance().createDBObject(
2246  session.get_currentUser(), td.tableName, TableDBObjectType, catalog);
2247 }
std::string tableName
void executeDryRun(const Catalog_Namespace::SessionInfo &session, TableDescriptor &td, std::list< ColumnDescriptor > &columns, std::vector< SharedDictionaryDef > &shared_dict_defs)
static const AccessPrivileges CREATE_TABLE
Definition: DBObject.h:151
Catalog & getCatalog() const
Definition: SessionInfo.h:90
specifies the content in-memory of a row in the table metadata table
bool checkDBAccessPrivileges(const DBObjectType &permissionType, const AccessPrivileges &privs, const std::string &objectName="") const
Definition: SessionInfo.cpp:24
std::unique_ptr< std::string > table_
Definition: ParserNode.h:996
const UserMetadata & get_currentUser() const
Definition: SessionInfo.h:93

+ Here is the call graph for this function:

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

Definition at line 2145 of file ParserNode.cpp.

References ColumnDescriptor::columnName, Data_Namespace::CPU_LEVEL, 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(), 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, TableDescriptor::tableName, and validate_shared_dictionary().

2148  {
2149  std::unordered_set<std::string> uc_col_names;
2150  const auto& catalog = session.getCatalog();
2151  const ShardKeyDef* shard_key_def{nullptr};
2152  for (auto& e : table_element_list_) {
2153  if (dynamic_cast<SharedDictionaryDef*>(e.get())) {
2154  auto shared_dict_def = static_cast<SharedDictionaryDef*>(e.get());
2156  this, shared_dict_def, columns, shared_dict_defs, catalog);
2157  shared_dict_defs.push_back(*shared_dict_def);
2158  continue;
2159  }
2160  if (dynamic_cast<ShardKeyDef*>(e.get())) {
2161  if (shard_key_def) {
2162  throw std::runtime_error("Specified more than one shard key");
2163  }
2164  shard_key_def = static_cast<const ShardKeyDef*>(e.get());
2165  continue;
2166  }
2167  if (!dynamic_cast<ColumnDef*>(e.get())) {
2168  throw std::runtime_error("Table constraints are not supported yet.");
2169  }
2170  ColumnDef* coldef = static_cast<ColumnDef*>(e.get());
2171  ColumnDescriptor cd;
2172  cd.columnName = *coldef->get_column_name();
2173  const auto uc_col_name = boost::to_upper_copy<std::string>(cd.columnName);
2174  if (reserved_keywords.find(uc_col_name) != reserved_keywords.end()) {
2175  throw std::runtime_error("Cannot create column with reserved keyword '" +
2176  cd.columnName + "'");
2177  }
2178  const auto it_ok = uc_col_names.insert(uc_col_name);
2179  if (!it_ok.second) {
2180  throw std::runtime_error("Column '" + cd.columnName + "' defined more than once");
2181  }
2182 
2183  setColumnDescriptor(cd, coldef);
2184  columns.push_back(cd);
2185  }
2186 
2187  td.tableName = *table_;
2188  td.nColumns = columns.size();
2189  td.isView = false;
2190  td.fragmenter = nullptr;
2196  if (shard_key_def) {
2197  td.shardedColumnId = shard_column_index(shard_key_def->get_column(), columns);
2198  if (!td.shardedColumnId) {
2199  throw std::runtime_error("Specified shard column " + shard_key_def->get_column() +
2200  " doesn't exist");
2201  }
2202  }
2203  if (is_temporary_) {
2205  } else {
2207  }
2208  if (!storage_options_.empty()) {
2209  for (auto& p : storage_options_) {
2210  get_table_definitions(td, p, columns);
2211  }
2212  }
2213  if (td.shardedColumnId && !td.nShards) {
2214  throw std::runtime_error("SHARD_COUNT needs to be specified with SHARD_KEY.");
2215  }
2216  td.keyMetainfo = serialize_key_metainfo(shard_key_def, shared_dict_defs);
2217 }
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:997
#define DEFAULT_MAX_ROWS
#define DEFAULT_PAGE_SIZE
specifies the content in-memory of a row in the column metadata table
std::string keyMetainfo
Catalog & getCatalog() const
Definition: SessionInfo.h:90
Fragmenter_Namespace::FragmenterType fragType
Data_Namespace::MemoryLevel persistenceLevel
std::list< std::unique_ptr< NameValueAssign > > storage_options_
Definition: ParserNode.h:1000
#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
Fragmenter_Namespace::AbstractFragmenter * fragmenter
std::string columnName
std::unique_ptr< std::string > table_
Definition: ParserNode.h:996
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:

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

Definition at line 984 of file ParserNode.h.

References table_.

Referenced by validate_shared_dictionary(), and validate_shared_dictionary_order().

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

+ Here is the caller graph for this function:

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

Definition at line 985 of file ParserNode.h.

References table_element_list_.

Referenced by validate_shared_dictionary().

985  {
986  return table_element_list_;
987  }
std::list< std::unique_ptr< TableElement > > table_element_list_
Definition: ParserNode.h:997

+ Here is the caller graph for this function:

Member Data Documentation

bool Parser::CreateTableStmt::if_not_exists_
private

Definition at line 999 of file ParserNode.h.

bool Parser::CreateTableStmt::is_temporary_
private

Definition at line 998 of file ParserNode.h.

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

Definition at line 1000 of file ParserNode.h.

Referenced by CreateTableStmt().

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

Definition at line 996 of file ParserNode.h.

Referenced by get_table().

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

Definition at line 997 of file ParserNode.h.

Referenced by CreateTableStmt(), and get_table_element_list().


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