OmniSciDB  a5dc49c757
 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, bool read_only_mode) 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 986 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 988 of file ParserNode.h.

References CHECK, storage_options_, and table_element_list_.

994  : table_(tab), is_temporary_(is_temporary), if_not_exists_(if_not_exists) {
995  CHECK(table_elems);
996  for (const auto e : *table_elems) {
997  table_element_list_.emplace_back(e);
998  }
999  delete table_elems;
1000  if (s) {
1001  for (const auto e : *s) {
1002  storage_options_.emplace_back(e);
1003  }
1004  delete s;
1005  }
1006  }
std::list< std::unique_ptr< TableElement > > table_element_list_
Definition: ParserNode.h:1025
std::list< std::unique_ptr< NameValueAssign > > storage_options_
Definition: ParserNode.h:1028
#define CHECK(condition)
Definition: Logger.h:291
std::unique_ptr< std::string > table_
Definition: ParserNode.h:1024
Parser::CreateTableStmt::CreateTableStmt ( const rapidjson::Value &  payload)

Definition at line 3250 of file ParserNode.cpp.

References CHECK, if_not_exists_, is_temporary_, json_bool(), json_str(), Parser::anonymous_namespace{ParserNode.cpp}::parse_elements(), Parser::anonymous_namespace{ParserNode.cpp}::parse_options(), storage_options_, table_, and table_element_list_.

3250  {
3251  CHECK(payload.HasMember("name"));
3252  table_ = std::make_unique<std::string>(json_str(payload["name"]));
3253  CHECK(payload.HasMember("elements"));
3254  CHECK(payload["elements"].IsArray());
3255 
3256  is_temporary_ = false;
3257  if (payload.HasMember("temporary")) {
3258  is_temporary_ = json_bool(payload["temporary"]);
3259  }
3260 
3261  if_not_exists_ = false;
3262  if (payload.HasMember("ifNotExists")) {
3263  if_not_exists_ = json_bool(payload["ifNotExists"]);
3264  }
3265 
3266  parse_elements(payload, "elements", *table_, table_element_list_);
3267 
3268  parse_options(payload, storage_options_);
3269 }
std::list< std::unique_ptr< TableElement > > table_element_list_
Definition: ParserNode.h:1025
const bool json_bool(const rapidjson::Value &obj) noexcept
Definition: JsonAccessors.h:51
const std::string json_str(const rapidjson::Value &obj) noexcept
Definition: JsonAccessors.h:46
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:1028
#define CHECK(condition)
Definition: Logger.h:291
std::unique_ptr< std::string > table_
Definition: ParserNode.h:1024

+ Here is the call graph for this function:

Member Function Documentation

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

Implements Parser::DDLStmt.

Definition at line 3329 of file ParserNode.cpp.

References Catalog_Namespace::SessionInfo::checkDBAccessPrivileges(), AccessPrivileges::CREATE_TABLE, executeDryRun(), Catalog_Namespace::SessionInfo::get_currentUser(), Catalog_Namespace::SessionInfo::getCatalog(), legacylockmgr::getExecuteWriteLock(), if_not_exists_, lockmgr::instance(), table_, TableDBObjectType, TableDescriptor::tableName, TableDescriptor::userId, and Catalog_Namespace::UserMetadata::userId.

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

3330  {
3331  if (read_only_mode) {
3332  throw std::runtime_error("CREATE TABLE invalid in read only mode.");
3333  }
3334  auto& catalog = session.getCatalog();
3335 
3336  // Until we create the table we don't have a table descriptor to lock and guarantee
3337  // exclusive use of. Because of that we need a global write lock to make sure we have
3338  // exclusive access to the system for now.
3339  const auto execute_write_lock = legacylockmgr::getExecuteWriteLock();
3340 
3341  // check access privileges
3344  throw std::runtime_error("Table " + *table_ +
3345  " will not be created. User has no create privileges.");
3346  }
3347 
3348  if (!catalog.validateNonExistentTableOrView(*table_, if_not_exists_)) {
3349  return;
3350  }
3351 
3352  TableDescriptor td;
3353  std::list<ColumnDescriptor> columns;
3354  std::vector<SharedDictionaryDef> shared_dict_defs;
3355 
3356  executeDryRun(session, td, columns, shared_dict_defs);
3357  td.userId = session.get_currentUser().userId;
3358 
3359  catalog.createShardedTable(td, columns, shared_dict_defs);
3360  // TODO (max): It's transactionally unsafe, should be fixed: we may create object w/o
3361  // privileges
3362  SysCatalog::instance().createDBObject(
3363  session.get_currentUser(), td.tableName, TableDBObjectType, catalog);
3364 }
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:158
Catalog & getCatalog() const
Definition: SessionInfo.h:75
T & instance()
Definition: LockMgr.cpp:101
auto getExecuteWriteLock()
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:1024
const UserMetadata & get_currentUser() const
Definition: SessionInfo.h:88

+ 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 3271 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(), is_temporary_, TableDescriptor::keyMetainfo, TableDescriptor::nShards, TableDescriptor::persistenceLevel, Parser::anonymous_namespace{ParserNode.cpp}::serialize_key_metainfo(), ddl_utils::set_default_table_attributes(), Parser::DDLStmt::setColumnDescriptor(), Parser::anonymous_namespace{ParserNode.cpp}::shard_column_index(), TableDescriptor::shardedColumnId, storage_options_, table_, table_element_list_, ddl_utils::validate_non_duplicate_column(), and validate_shared_dictionary().

Referenced by execute().

3274  {
3275  std::unordered_set<std::string> uc_col_names;
3276  const auto& catalog = session.getCatalog();
3277  const ShardKeyDef* shard_key_def{nullptr};
3278  for (auto& e : table_element_list_) {
3279  if (dynamic_cast<SharedDictionaryDef*>(e.get())) {
3280  auto shared_dict_def = static_cast<SharedDictionaryDef*>(e.get());
3282  this, shared_dict_def, columns, shared_dict_defs, catalog);
3283  shared_dict_defs.push_back(*shared_dict_def);
3284  continue;
3285  }
3286  if (dynamic_cast<ShardKeyDef*>(e.get())) {
3287  if (shard_key_def) {
3288  throw std::runtime_error("Specified more than one shard key");
3289  }
3290  shard_key_def = static_cast<const ShardKeyDef*>(e.get());
3291  continue;
3292  }
3293  if (!dynamic_cast<ColumnDef*>(e.get())) {
3294  throw std::runtime_error("Table constraints are not supported yet.");
3295  }
3296  ColumnDef* coldef = static_cast<ColumnDef*>(e.get());
3297  ColumnDescriptor cd;
3298  cd.columnName = *coldef->get_column_name();
3300  setColumnDescriptor(cd, coldef);
3301  columns.push_back(cd);
3302  }
3303 
3304  ddl_utils::set_default_table_attributes(*table_, td, columns.size());
3305 
3306  if (shard_key_def) {
3307  td.shardedColumnId = shard_column_index(shard_key_def->get_column(), columns);
3308  if (!td.shardedColumnId) {
3309  throw std::runtime_error("Specified shard column " + shard_key_def->get_column() +
3310  " doesn't exist");
3311  }
3312  }
3313  if (is_temporary_) {
3315  } else {
3317  }
3318  if (!storage_options_.empty()) {
3319  for (auto& p : storage_options_) {
3320  get_table_definitions(td, p, columns);
3321  }
3322  }
3323  if (td.shardedColumnId && !td.nShards) {
3324  throw std::runtime_error("SHARD_COUNT needs to be specified with SHARD_KEY.");
3325  }
3326  td.keyMetainfo = serialize_key_metainfo(shard_key_def, shared_dict_defs);
3327 }
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:1025
void validate_non_duplicate_column(const std::string &column_name, std::unordered_set< std::string > &upper_column_names)
Definition: DdlUtils.cpp:728
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:714
Catalog & getCatalog() const
Definition: SessionInfo.h:75
Data_Namespace::MemoryLevel persistenceLevel
std::list< std::unique_ptr< NameValueAssign > > storage_options_
Definition: ParserNode.h:1028
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:1024
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:

+ Here is the caller graph for this function:

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

Implements Parser::CreateTableBaseStmt.

Definition at line 1010 of file ParserNode.h.

References table_.

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

Implements Parser::CreateTableBaseStmt.

Definition at line 1011 of file ParserNode.h.

References table_element_list_.

1012  {
1013  return table_element_list_;
1014  }
std::list< std::unique_ptr< TableElement > > table_element_list_
Definition: ParserNode.h:1025

Member Data Documentation

bool Parser::CreateTableStmt::if_not_exists_
private

Definition at line 1027 of file ParserNode.h.

Referenced by CreateTableStmt(), and execute().

bool Parser::CreateTableStmt::is_temporary_
private

Definition at line 1026 of file ParserNode.h.

Referenced by CreateTableStmt(), and executeDryRun().

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

Definition at line 1028 of file ParserNode.h.

Referenced by CreateTableStmt(), and executeDryRun().

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

Definition at line 1024 of file ParserNode.h.

Referenced by CreateTableStmt(), execute(), executeDryRun(), and get_table().

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

Definition at line 1025 of file ParserNode.h.

Referenced by CreateTableStmt(), executeDryRun(), and get_table_element_list().


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