OmniSciDB  c1a53651b2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Parser::CreateDataframeStmt Class Reference

#include <ParserNode.h>

+ Inheritance diagram for Parser::CreateDataframeStmt:
+ Collaboration diagram for Parser::CreateDataframeStmt:

Public Member Functions

 CreateDataframeStmt (std::string *tab, std::list< TableElement * > *table_elems, std::string *filename, std::list< NameValueAssign * > *s)
 
 CreateDataframeStmt (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
 
- 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_
 
std::unique_ptr< std::string > filename_
 
std::list< std::unique_ptr
< NameValueAssign > > 
storage_options_
 

Detailed Description

Definition at line 1085 of file ParserNode.h.

Constructor & Destructor Documentation

Parser::CreateDataframeStmt::CreateDataframeStmt ( std::string *  tab,
std::list< TableElement * > *  table_elems,
std::string *  filename,
std::list< NameValueAssign * > *  s 
)
inline

Definition at line 1087 of file ParserNode.h.

References CHECK, storage_options_, and table_element_list_.

1091  : table_(tab), filename_(filename) {
1092  CHECK(table_elems);
1093  for (const auto e : *table_elems) {
1094  table_element_list_.emplace_back(e);
1095  }
1096  delete table_elems;
1097  if (s) {
1098  for (const auto e : *s) {
1099  storage_options_.emplace_back(e);
1100  }
1101  delete s;
1102  }
1103  }
std::list< std::unique_ptr< NameValueAssign > > storage_options_
Definition: ParserNode.h:1119
std::unique_ptr< std::string > table_
Definition: ParserNode.h:1116
#define CHECK(condition)
Definition: Logger.h:291
std::list< std::unique_ptr< TableElement > > table_element_list_
Definition: ParserNode.h:1117
std::unique_ptr< std::string > filename_
Definition: ParserNode.h:1118
Parser::CreateDataframeStmt::CreateDataframeStmt ( const rapidjson::Value &  payload)

Definition at line 3309 of file ParserNode.cpp.

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

3309  {
3310  CHECK(payload.HasMember("name"));
3311  table_ = std::make_unique<std::string>(json_str(payload["name"]));
3312 
3313  CHECK(payload.HasMember("elementList"));
3314  parse_elements(payload, "elementList", *table_, table_element_list_);
3315 
3316  CHECK(payload.HasMember("filePath"));
3317  std::string fs = json_str(payload["filePath"]);
3318  // strip leading/trailing spaces/quotes/single quotes
3319  boost::algorithm::trim_if(fs, boost::is_any_of(" \"'`"));
3320  filename_ = std::make_unique<std::string>(fs);
3321 
3322  parse_options(payload, storage_options_);
3323 }
std::list< std::unique_ptr< NameValueAssign > > storage_options_
Definition: ParserNode.h:1119
const std::string json_str(const rapidjson::Value &obj) noexcept
Definition: JsonAccessors.h:44
std::unique_ptr< std::string > table_
Definition: ParserNode.h:1116
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)
#define CHECK(condition)
Definition: Logger.h:291
std::list< std::unique_ptr< TableElement > > table_element_list_
Definition: ParserNode.h:1117
std::unique_ptr< std::string > filename_
Definition: ParserNode.h:1118

+ Here is the call graph for this function:

Member Function Documentation

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

Implements Parser::DDLStmt.

Definition at line 3325 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, legacylockmgr::ExecutorOuterLock, filename_, TableDescriptor::fragmenter, TableDescriptor::fragPageSize, TableDescriptor::fragType, Parser::ColumnDef::get_column_name(), Catalog_Namespace::SessionInfo::get_currentUser(), Parser::anonymous_namespace{ParserNode.cpp}::get_dataframe_definitions(), Catalog_Namespace::SessionInfo::getCatalog(), legacylockmgr::LockMgr< MutexType, KeyType >::getMutex(), Fragmenter_Namespace::INSERT_ORDER, TableDescriptor::isView, TableDescriptor::keyMetainfo, TableDescriptor::maxChunkSize, TableDescriptor::maxFragRows, TableDescriptor::maxRows, TableDescriptor::nColumns, TableDescriptor::persistenceLevel, Parser::anonymous_namespace{ParserNode.cpp}::serialize_key_metainfo(), Parser::DDLStmt::setColumnDescriptor(), storage_options_, TableDescriptor::storageType, table_, table_element_list_, TableDBObjectType, TableDescriptor::tableName, TableDescriptor::userId, Catalog_Namespace::UserMetadata::userId, and validate_shared_dictionary().

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

3326  {
3327  if (read_only_mode) {
3328  throw std::runtime_error("CREATE DATAFRAME invalid in read only mode.");
3329  }
3330  auto& catalog = session.getCatalog();
3331 
3332  const auto execute_write_lock =
3336 
3337  // check access privileges
3340  throw std::runtime_error("Table " + *table_ +
3341  " will not be created. User has no create privileges.");
3342  }
3343 
3344  if (catalog.getMetadataForTable(*table_) != nullptr) {
3345  throw std::runtime_error("Table " + *table_ + " already exists.");
3346  }
3348  std::list<ColumnDescriptor> columns;
3349  std::vector<SharedDictionaryDef> shared_dict_defs;
3350 
3351  std::unordered_set<std::string> uc_col_names;
3352  for (auto& e : table_element_list_) {
3353  if (dynamic_cast<SharedDictionaryDef*>(e.get())) {
3354  auto shared_dict_def = static_cast<SharedDictionaryDef*>(e.get());
3356  this, shared_dict_def, columns, shared_dict_defs, catalog);
3357  shared_dict_defs.push_back(*shared_dict_def);
3358  continue;
3359  }
3360  if (!dynamic_cast<ColumnDef*>(e.get())) {
3361  throw std::runtime_error("Table constraints are not supported yet.");
3362  }
3363  ColumnDef* coldef = static_cast<ColumnDef*>(e.get());
3364  ColumnDescriptor cd;
3365  cd.columnName = *coldef->get_column_name();
3366  const auto uc_col_name = boost::to_upper_copy<std::string>(cd.columnName);
3367  const auto it_ok = uc_col_names.insert(uc_col_name);
3368  if (!it_ok.second) {
3369  throw std::runtime_error("Column '" + cd.columnName + "' defined more than once");
3370  }
3371  setColumnDescriptor(cd, coldef);
3372  columns.push_back(cd);
3373  }
3374 
3375  df_td.tableName = *table_;
3376  df_td.nColumns = columns.size();
3377  df_td.isView = false;
3378  df_td.fragmenter = nullptr;
3383  df_td.maxRows = DEFAULT_MAX_ROWS;
3385  if (!storage_options_.empty()) {
3386  for (auto& p : storage_options_) {
3387  get_dataframe_definitions(df_td, p, columns);
3388  }
3389  }
3390  df_td.keyMetainfo = serialize_key_metainfo(nullptr, shared_dict_defs);
3391  df_td.userId = session.get_currentUser().userId;
3392  df_td.storageType = *filename_;
3393 
3394  catalog.createShardedTable(df_td, columns, shared_dict_defs);
3395  // TODO (max): It's transactionally unsafe, should be fixed: we may create object w/o
3396  // privileges
3397  SysCatalog::instance().createDBObject(
3398  session.get_currentUser(), df_td.tableName, TableDBObjectType, catalog);
3399 }
static std::shared_ptr< WrapperType< MutexType > > getMutex(const LockType lockType, const KeyType &key)
std::list< std::unique_ptr< NameValueAssign > > storage_options_
Definition: ParserNode.h:1119
void setColumnDescriptor(ColumnDescriptor &cd, const ColumnDef *coldef)
std::string tableName
std::string storageType
#define DEFAULT_MAX_CHUNK_SIZE
std::unique_ptr< std::string > table_
Definition: ParserNode.h:1116
#define DEFAULT_MAX_ROWS
void get_dataframe_definitions(DataframeTableDescriptor &df_td, const std::unique_ptr< NameValueAssign > &p, const std::list< ColumnDescriptor > &columns)
std::unique_lock< T > unique_lock
specifies the content in-memory of a row in the column metadata table
static const AccessPrivileges CREATE_TABLE
Definition: DBObject.h:158
std::string keyMetainfo
std::shared_ptr< Fragmenter_Namespace::AbstractFragmenter > fragmenter
#define DEFAULT_PAGE_SIZE
Catalog & getCatalog() const
Definition: SessionInfo.h:75
#define DEFAULT_FRAGMENT_ROWS
Fragmenter_Namespace::FragmenterType fragType
Data_Namespace::MemoryLevel persistenceLevel
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)
bool checkDBAccessPrivileges(const DBObjectType &permissionType, const AccessPrivileges &privs, const std::string &objectName="") const
Definition: SessionInfo.cpp:24
std::list< std::unique_ptr< TableElement > > table_element_list_
Definition: ParserNode.h:1117
std::string columnName
const UserMetadata & get_currentUser() const
Definition: SessionInfo.h:88
std::unique_ptr< std::string > filename_
Definition: ParserNode.h:1118
std::string serialize_key_metainfo(const ShardKeyDef *shard_key_def, const std::vector< SharedDictionaryDef > &shared_dict_defs)
specifies the content in-memory of a row in the table metadata table

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Implements Parser::CreateTableBaseStmt.

Definition at line 1106 of file ParserNode.h.

References table_.

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

Implements Parser::CreateTableBaseStmt.

Definition at line 1107 of file ParserNode.h.

References table_element_list_.

1108  {
1109  return table_element_list_;
1110  }
std::list< std::unique_ptr< TableElement > > table_element_list_
Definition: ParserNode.h:1117

Member Data Documentation

std::unique_ptr<std::string> Parser::CreateDataframeStmt::filename_
private

Definition at line 1118 of file ParserNode.h.

Referenced by CreateDataframeStmt(), and execute().

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

Definition at line 1119 of file ParserNode.h.

Referenced by CreateDataframeStmt(), and execute().

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

Definition at line 1116 of file ParserNode.h.

Referenced by CreateDataframeStmt(), execute(), and get_table().

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

Definition at line 1117 of file ParserNode.h.

Referenced by CreateDataframeStmt(), execute(), and get_table_element_list().


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