OmniSciDB  04ee39c94c
Parser::CreateTableAsSelectStmt Class Reference

#include <ParserNode.h>

+ Inheritance diagram for Parser::CreateTableAsSelectStmt:
+ Collaboration diagram for Parser::CreateTableAsSelectStmt:

Public Member Functions

 CreateTableAsSelectStmt (const std::string *table_name, const std::string *select_query, const bool is_temporary, const bool if_not_exists, std::list< NameValueAssign *> *s)
 
void execute (const Catalog_Namespace::SessionInfo &session) override
 
- Public Member Functions inherited from Parser::InsertIntoTableAsSelectStmt
 InsertIntoTableAsSelectStmt (const std::string *table_name, const std::string *select_query, std::list< std::string *> *c)
 
void populateData (const Catalog_Namespace::SessionInfo &session, bool is_temporary, bool validate_table)
 
std::string & get_table ()
 
std::string & get_select_query ()
 
- 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

const bool is_temporary_
 
const bool if_not_exists_
 
std::list< std::unique_ptr< NameValueAssign > > storage_options_
 

Additional Inherited Members

- Public Attributes inherited from Parser::InsertIntoTableAsSelectStmt
DistributedConnectorleafs_connector_ = nullptr
 
- Protected Attributes inherited from Parser::InsertIntoTableAsSelectStmt
std::vector< std::unique_ptr< std::string > > column_list_
 
std::string table_name_
 
std::string select_query_
 

Detailed Description

Definition at line 1063 of file ParserNode.h.

Constructor & Destructor Documentation

◆ CreateTableAsSelectStmt()

Parser::CreateTableAsSelectStmt::CreateTableAsSelectStmt ( const std::string *  table_name,
const std::string *  select_query,
const bool  is_temporary,
const bool  if_not_exists,
std::list< NameValueAssign *> *  s 
)
inline

Definition at line 1065 of file ParserNode.h.

References session.

1070  : InsertIntoTableAsSelectStmt(table_name, select_query, nullptr)
1071  , is_temporary_(is_temporary)
1072  , if_not_exists_(if_not_exists) {
1073  if (s) {
1074  for (const auto& e : *s) {
1075  storage_options_.emplace_back(e);
1076  }
1077  delete s;
1078  }
1079  }
InsertIntoTableAsSelectStmt(const std::string *table_name, const std::string *select_query, std::list< std::string *> *c)
Definition: ParserNode.h:995
std::list< std::unique_ptr< NameValueAssign > > storage_options_
Definition: ParserNode.h:1086

Member Function Documentation

◆ execute()

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

Reimplemented from Parser::InsertIntoTableAsSelectStmt.

Definition at line 2694 of file ParserNode.cpp.

References Catalog_Namespace::SessionInfo::checkDBAccessPrivileges(), Data_Namespace::CPU_LEVEL, AccessPrivileges::CREATE_TABLE, DEFAULT_FRAGMENT_ROWS, DEFAULT_MAX_CHUNK_SIZE, DEFAULT_MAX_ROWS, DEFAULT_PAGE_SIZE, Data_Namespace::DISK_LEVEL, TableDescriptor::fragmenter, TableDescriptor::fragPageSize, TableDescriptor::fragType, g_cluster, Catalog_Namespace::SessionInfo::get_currentUser(), Parser::anonymous_namespace{ParserNode.cpp}::get_table_definitions(), Catalog_Namespace::SessionInfo::getCatalog(), Parser::InsertIntoTableAsSelectStmt::LocalConnector::getColumnDescriptors(), Fragmenter_Namespace::INSERT_ORDER, TableDescriptor::isView, TableDescriptor::keyMetainfo, TableDescriptor::maxChunkSize, TableDescriptor::maxFragRows, TableDescriptor::maxRows, TableDescriptor::nColumns, TableDescriptor::persistenceLevel, Parser::InsertIntoTableAsSelectStmt::LocalConnector::query(), run-benchmark-import::result, TableDBObjectType, TableDescriptor::tableName, TableDescriptor::userId, and Catalog_Namespace::UserMetadata::userId.

2694  {
2695  LocalConnector local_connector;
2696  auto& catalog = session.getCatalog();
2697  bool create_table = nullptr == leafs_connector_;
2698 
2699  if (create_table) {
2700  // check access privileges
2703  throw std::runtime_error("CTAS failed. Table " + table_name_ +
2704  " will not be created. User has no create privileges.");
2705  }
2706 
2707  if (catalog.getMetadataForTable(table_name_) != nullptr) {
2708  throw std::runtime_error("Table " + table_name_ +
2709  " already exists and no data was loaded.");
2710  }
2711 
2712  // only validate the select query so we get the target types
2713  // correctly, but do not populate the result set
2714  auto result = local_connector.query(session, select_query_, true);
2715  const auto column_descriptors_for_create =
2716  local_connector.getColumnDescriptors(result, true);
2717 
2718  TableDescriptor td;
2719  td.tableName = table_name_;
2720  td.userId = session.get_currentUser().userId;
2721  td.nColumns = column_descriptors_for_create.size();
2722  td.isView = false;
2723  td.fragmenter = nullptr;
2729  td.keyMetainfo = "[]";
2730  if (is_temporary_) {
2732  } else {
2734  }
2735 
2736  if (!storage_options_.empty()) {
2737  for (auto& p : storage_options_) {
2738  get_table_definitions(td, p, column_descriptors_for_create);
2739  }
2740  }
2741 
2742  catalog.createTable(td, column_descriptors_for_create, {}, true);
2743  // TODO (max): It's transactionally unsafe, should be fixed: we may create object
2744  // w/o privileges
2745  SysCatalog::instance().createDBObject(
2746  session.get_currentUser(), td.tableName, TableDBObjectType, catalog);
2747  }
2748 
2749  try {
2750  populateData(session, is_temporary_, false);
2751  } catch (...) {
2752  if (!g_cluster) {
2753  const TableDescriptor* created_td = catalog.getMetadataForTable(table_name_);
2754  if (created_td) {
2755  catalog.dropTable(created_td);
2756  }
2757  }
2758  throw;
2759  }
2760 }
std::string tableName
#define DEFAULT_MAX_ROWS
const UserMetadata & get_currentUser() const
Definition: SessionInfo.h:93
void populateData(const Catalog_Namespace::SessionInfo &session, bool is_temporary, bool validate_table)
std::list< std::unique_ptr< NameValueAssign > > storage_options_
Definition: ParserNode.h:1086
Catalog & getCatalog() const
Definition: SessionInfo.h:90
#define DEFAULT_PAGE_SIZE
static const AccessPrivileges CREATE_TABLE
Definition: DBObject.h:151
std::string keyMetainfo
Fragmenter_Namespace::FragmenterType fragType
Data_Namespace::MemoryLevel persistenceLevel
bool checkDBAccessPrivileges(const DBObjectType &permissionType, const AccessPrivileges &privs, const std::string &objectName="") const
Definition: SessionInfo.cpp:24
#define DEFAULT_FRAGMENT_ROWS
DistributedConnector * leafs_connector_
Definition: ParserNode.h:1051
void get_table_definitions(TableDescriptor &td, const std::unique_ptr< NameValueAssign > &p, const std::list< ColumnDescriptor > &columns)
bool g_cluster
#define DEFAULT_MAX_CHUNK_SIZE
specifies the content in-memory of a row in the table metadata table
Fragmenter_Namespace::AbstractFragmenter * fragmenter
+ Here is the call graph for this function:

Member Data Documentation

◆ if_not_exists_

const bool Parser::CreateTableAsSelectStmt::if_not_exists_
private

Definition at line 1085 of file ParserNode.h.

◆ is_temporary_

const bool Parser::CreateTableAsSelectStmt::is_temporary_
private

Definition at line 1084 of file ParserNode.h.

◆ storage_options_

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

Definition at line 1086 of file ParserNode.h.


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