OmniSciDB  eb3a3d0a03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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, const std::string *storage, std::list< TableElement * > *table_elems, bool is_temporary, bool if_not_exists, std::list< NameValueAssign * > *s)
 
 CreateTableStmt (const rapidjson::Value &payload)
 
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 982 of file ParserNode.h.

Constructor & Destructor Documentation

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

References CHECK, storage_options_, and table_element_list_.

990  : table_(tab), is_temporary_(is_temporary), if_not_exists_(if_not_exists) {
991  CHECK(table_elems);
992  for (const auto e : *table_elems) {
993  table_element_list_.emplace_back(e);
994  }
995  delete table_elems;
996  if (s) {
997  for (const auto e : *s) {
998  storage_options_.emplace_back(e);
999  }
1000  delete s;
1001  }
1002  }
std::list< std::unique_ptr< TableElement > > table_element_list_
Definition: ParserNode.h:1020
std::list< std::unique_ptr< NameValueAssign > > storage_options_
Definition: ParserNode.h:1023
#define CHECK(condition)
Definition: Logger.h:209
std::unique_ptr< std::string > table_
Definition: ParserNode.h:1019
Parser::CreateTableStmt::CreateTableStmt ( const rapidjson::Value &  payload)

Definition at line 2471 of file ParserNode.cpp.

References CHECK, json_bool(), json_str(), Parser::anonymous_namespace{ParserNode.cpp}::parse_elements(), and Parser::anonymous_namespace{ParserNode.cpp}::parse_options().

2471  {
2472  CHECK(payload.HasMember("name"));
2473  table_ = std::make_unique<std::string>(json_str(payload["name"]));
2474  CHECK(payload.HasMember("elements"));
2475  CHECK(payload["elements"].IsArray());
2476 
2477  is_temporary_ = false;
2478  if (payload.HasMember("temporary")) {
2479  is_temporary_ = json_bool(payload["temporary"]);
2480  }
2481 
2482  if_not_exists_ = false;
2483  if (payload.HasMember("ifNotExists")) {
2484  if_not_exists_ = json_bool(payload["ifNotExists"]);
2485  }
2486 
2487  parse_elements(payload, "elements", *table_, table_element_list_);
2488 
2489  parse_options(payload, storage_options_);
2490 }
std::list< std::unique_ptr< TableElement > > table_element_list_
Definition: ParserNode.h:1020
const bool json_bool(const rapidjson::Value &obj) noexcept
Definition: JsonAccessors.h:49
const std::string json_str(const rapidjson::Value &obj) noexcept
Definition: JsonAccessors.h:44
void parse_elements(const rapidjson::Value &payload, std::string element_name, std::string &table_name, std::list< std::unique_ptr< TableElement >> &table_element_list)
void parse_options(const rapidjson::Value &payload, std::list< std::unique_ptr< NameValueAssign >> &nameValueList, bool stringToNull=false, bool stringToInteger=false)
std::list< std::unique_ptr< NameValueAssign > > storage_options_
Definition: ParserNode.h:1023
#define CHECK(condition)
Definition: Logger.h:209
std::unique_ptr< std::string > table_
Definition: ParserNode.h:1019

+ 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 2550 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.

Referenced by omnisci.cursor.Cursor::executemany().

2550  {
2551  auto& catalog = session.getCatalog();
2552 
2553  const auto execute_write_lock = mapd_unique_lock<mapd_shared_mutex>(
2556 
2557  // check access privileges
2560  throw std::runtime_error("Table " + *table_ +
2561  " will not be created. User has no create privileges.");
2562  }
2563 
2564  if (!catalog.validateNonExistentTableOrView(*table_, if_not_exists_)) {
2565  return;
2566  }
2567 
2568  TableDescriptor td;
2569  std::list<ColumnDescriptor> columns;
2570  std::vector<SharedDictionaryDef> shared_dict_defs;
2571 
2572  executeDryRun(session, td, columns, shared_dict_defs);
2573  td.userId = session.get_currentUser().userId;
2574 
2575  catalog.createShardedTable(td, columns, shared_dict_defs);
2576  // TODO (max): It's transactionally unsafe, should be fixed: we may create object w/o
2577  // privileges
2578  SysCatalog::instance().createDBObject(
2579  session.get_currentUser(), td.tableName, TableDBObjectType, catalog);
2580 }
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:160
Catalog & getCatalog() const
Definition: SessionInfo.h:67
static std::shared_ptr< MutexType > getMutex(const LockType lockType, const KeyType &key)
Definition: LegacyLockMgr.h:51
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:1019
const UserMetadata & get_currentUser() const
Definition: SessionInfo.h:73

+ Here is the call graph for this function:

+ Here is the caller 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 2492 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().

2495  {
2496  std::unordered_set<std::string> uc_col_names;
2497  const auto& catalog = session.getCatalog();
2498  const ShardKeyDef* shard_key_def{nullptr};
2499  for (auto& e : table_element_list_) {
2500  if (dynamic_cast<SharedDictionaryDef*>(e.get())) {
2501  auto shared_dict_def = static_cast<SharedDictionaryDef*>(e.get());
2503  this, shared_dict_def, columns, shared_dict_defs, catalog);
2504  shared_dict_defs.push_back(*shared_dict_def);
2505  continue;
2506  }
2507  if (dynamic_cast<ShardKeyDef*>(e.get())) {
2508  if (shard_key_def) {
2509  throw std::runtime_error("Specified more than one shard key");
2510  }
2511  shard_key_def = static_cast<const ShardKeyDef*>(e.get());
2512  continue;
2513  }
2514  if (!dynamic_cast<ColumnDef*>(e.get())) {
2515  throw std::runtime_error("Table constraints are not supported yet.");
2516  }
2517  ColumnDef* coldef = static_cast<ColumnDef*>(e.get());
2518  ColumnDescriptor cd;
2519  cd.columnName = *coldef->get_column_name();
2521  setColumnDescriptor(cd, coldef);
2522  columns.push_back(cd);
2523  }
2524 
2525  ddl_utils::set_default_table_attributes(*table_, td, columns.size());
2526 
2527  if (shard_key_def) {
2528  td.shardedColumnId = shard_column_index(shard_key_def->get_column(), columns);
2529  if (!td.shardedColumnId) {
2530  throw std::runtime_error("Specified shard column " + shard_key_def->get_column() +
2531  " doesn't exist");
2532  }
2533  }
2534  if (is_temporary_) {
2536  } else {
2538  }
2539  if (!storage_options_.empty()) {
2540  for (auto& p : storage_options_) {
2541  get_table_definitions(td, p, columns);
2542  }
2543  }
2544  if (td.shardedColumnId && !td.nShards) {
2545  throw std::runtime_error("SHARD_COUNT needs to be specified with SHARD_KEY.");
2546  }
2547  td.keyMetainfo = serialize_key_metainfo(shard_key_def, shared_dict_defs);
2548 }
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:1020
void validate_non_duplicate_column(const std::string &column_name, std::unordered_set< std::string > &upper_column_names)
Definition: DdlUtils.cpp:633
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:619
Catalog & getCatalog() const
Definition: SessionInfo.h:67
Data_Namespace::MemoryLevel persistenceLevel
std::list< std::unique_ptr< NameValueAssign > > storage_options_
Definition: ParserNode.h:1023
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:1019
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:

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

Implements Parser::CreateTableBaseStmt.

Definition at line 1006 of file ParserNode.h.

References table_.

1006 { return table_.get(); }
std::unique_ptr< std::string > table_
Definition: ParserNode.h:1019
const std::list<std::unique_ptr<TableElement> >& Parser::CreateTableStmt::get_table_element_list ( ) const
inlineoverridevirtual

Implements Parser::CreateTableBaseStmt.

Definition at line 1007 of file ParserNode.h.

References table_element_list_.

1008  {
1009  return table_element_list_;
1010  }
std::list< std::unique_ptr< TableElement > > table_element_list_
Definition: ParserNode.h:1020

Member Data Documentation

bool Parser::CreateTableStmt::if_not_exists_
private

Definition at line 1022 of file ParserNode.h.

bool Parser::CreateTableStmt::is_temporary_
private

Definition at line 1021 of file ParserNode.h.

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

Definition at line 1023 of file ParserNode.h.

Referenced by CreateTableStmt().

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

Definition at line 1019 of file ParserNode.h.

Referenced by get_table().

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

Definition at line 1020 of file ParserNode.h.

Referenced by CreateTableStmt(), and get_table_element_list().


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