OmniSciDB  eb3a3d0a03
 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) 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 1070 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 1072 of file ParserNode.h.

References CHECK, storage_options_, and table_element_list_.

1076  : table_(tab), filename_(filename) {
1077  CHECK(table_elems);
1078  for (const auto e : *table_elems) {
1079  table_element_list_.emplace_back(e);
1080  }
1081  delete table_elems;
1082  if (s) {
1083  for (const auto e : *s) {
1084  storage_options_.emplace_back(e);
1085  }
1086  delete s;
1087  }
1088  }
std::list< std::unique_ptr< NameValueAssign > > storage_options_
Definition: ParserNode.h:1103
std::unique_ptr< std::string > table_
Definition: ParserNode.h:1100
#define CHECK(condition)
Definition: Logger.h:209
std::list< std::unique_ptr< TableElement > > table_element_list_
Definition: ParserNode.h:1101
std::unique_ptr< std::string > filename_
Definition: ParserNode.h:1102
Parser::CreateDataframeStmt::CreateDataframeStmt ( const rapidjson::Value &  payload)

Definition at line 2582 of file ParserNode.cpp.

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

2582  {
2583  CHECK(payload.HasMember("name"));
2584  table_ = std::make_unique<std::string>(json_str(payload["name"]));
2585 
2586  CHECK(payload.HasMember("elementList"));
2587  parse_elements(payload, "elementList", *table_, table_element_list_);
2588 
2589  CHECK(payload.HasMember("filePath"));
2590  std::string fs = json_str(payload["filePath"]);
2591  // strip leading/trailing spaces/quotes/single quotes
2592  boost::algorithm::trim_if(fs, boost::is_any_of(" \"'`"));
2593  filename_ = std::make_unique<std::string>(fs);
2594 
2595  parse_options(payload, storage_options_);
2596 }
std::list< std::unique_ptr< NameValueAssign > > storage_options_
Definition: ParserNode.h:1103
const std::string json_str(const rapidjson::Value &obj) noexcept
Definition: JsonAccessors.h:44
std::unique_ptr< std::string > table_
Definition: ParserNode.h:1100
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:209
std::list< std::unique_ptr< TableElement > > table_element_list_
Definition: ParserNode.h:1101
std::unique_ptr< std::string > filename_
Definition: ParserNode.h:1102

+ Here is the call graph for this function:

Member Function Documentation

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

Implements Parser::DDLStmt.

Definition at line 2598 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, 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(), TableDescriptor::storageType, TableDBObjectType, TableDescriptor::tableName, TableDescriptor::userId, Catalog_Namespace::UserMetadata::userId, and validate_shared_dictionary().

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

2598  {
2599  auto& catalog = session.getCatalog();
2600 
2601  const auto execute_write_lock = mapd_unique_lock<mapd_shared_mutex>(
2604 
2605  // check access privileges
2608  throw std::runtime_error("Table " + *table_ +
2609  " will not be created. User has no create privileges.");
2610  }
2611 
2612  if (catalog.getMetadataForTable(*table_) != nullptr) {
2613  throw std::runtime_error("Table " + *table_ + " already exists.");
2614  }
2616  std::list<ColumnDescriptor> columns;
2617  std::vector<SharedDictionaryDef> shared_dict_defs;
2618 
2619  std::unordered_set<std::string> uc_col_names;
2620  for (auto& e : table_element_list_) {
2621  if (dynamic_cast<SharedDictionaryDef*>(e.get())) {
2622  auto shared_dict_def = static_cast<SharedDictionaryDef*>(e.get());
2624  this, shared_dict_def, columns, shared_dict_defs, catalog);
2625  shared_dict_defs.push_back(*shared_dict_def);
2626  continue;
2627  }
2628  if (!dynamic_cast<ColumnDef*>(e.get())) {
2629  throw std::runtime_error("Table constraints are not supported yet.");
2630  }
2631  ColumnDef* coldef = static_cast<ColumnDef*>(e.get());
2632  ColumnDescriptor cd;
2633  cd.columnName = *coldef->get_column_name();
2634  const auto uc_col_name = boost::to_upper_copy<std::string>(cd.columnName);
2635  const auto it_ok = uc_col_names.insert(uc_col_name);
2636  if (!it_ok.second) {
2637  throw std::runtime_error("Column '" + cd.columnName + "' defined more than once");
2638  }
2639  setColumnDescriptor(cd, coldef);
2640  columns.push_back(cd);
2641  }
2642 
2643  df_td.tableName = *table_;
2644  df_td.nColumns = columns.size();
2645  df_td.isView = false;
2646  df_td.fragmenter = nullptr;
2651  df_td.maxRows = DEFAULT_MAX_ROWS;
2653  if (!storage_options_.empty()) {
2654  for (auto& p : storage_options_) {
2655  get_dataframe_definitions(df_td, p, columns);
2656  }
2657  }
2658  df_td.keyMetainfo = serialize_key_metainfo(nullptr, shared_dict_defs);
2659  df_td.userId = session.get_currentUser().userId;
2660  df_td.storageType = *filename_;
2661 
2662  catalog.createShardedTable(df_td, columns, shared_dict_defs);
2663  // TODO (max): It's transactionally unsafe, should be fixed: we may create object w/o
2664  // privileges
2665  SysCatalog::instance().createDBObject(
2666  session.get_currentUser(), df_td.tableName, TableDBObjectType, catalog);
2667 }
std::list< std::unique_ptr< NameValueAssign > > storage_options_
Definition: ParserNode.h:1103
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:1100
#define DEFAULT_MAX_ROWS
void get_dataframe_definitions(DataframeTableDescriptor &df_td, const std::unique_ptr< NameValueAssign > &p, const std::list< ColumnDescriptor > &columns)
specifies the content in-memory of a row in the column metadata table
static const AccessPrivileges CREATE_TABLE
Definition: DBObject.h:160
std::string keyMetainfo
std::shared_ptr< Fragmenter_Namespace::AbstractFragmenter > fragmenter
#define DEFAULT_PAGE_SIZE
Catalog & getCatalog() const
Definition: SessionInfo.h:67
#define DEFAULT_FRAGMENT_ROWS
Fragmenter_Namespace::FragmenterType fragType
Data_Namespace::MemoryLevel persistenceLevel
static std::shared_ptr< MutexType > getMutex(const LockType lockType, const KeyType &key)
Definition: LegacyLockMgr.h:51
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:1101
std::string columnName
const UserMetadata & get_currentUser() const
Definition: SessionInfo.h:73
std::unique_ptr< std::string > filename_
Definition: ParserNode.h:1102
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 1091 of file ParserNode.h.

References table_.

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

Implements Parser::CreateTableBaseStmt.

Definition at line 1092 of file ParserNode.h.

References table_element_list_.

1093  {
1094  return table_element_list_;
1095  }
std::list< std::unique_ptr< TableElement > > table_element_list_
Definition: ParserNode.h:1101

Member Data Documentation

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

Definition at line 1102 of file ParserNode.h.

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

Definition at line 1103 of file ParserNode.h.

Referenced by CreateDataframeStmt().

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

Definition at line 1100 of file ParserNode.h.

Referenced by get_table().

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

Definition at line 1101 of file ParserNode.h.

Referenced by CreateDataframeStmt(), and get_table_element_list().


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