OmniSciDB  2c44a3935d
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 (QueryStateProxy, 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 1108 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 1110 of file ParserNode.h.

1115  : InsertIntoTableAsSelectStmt(table_name, select_query, nullptr)
1116  , is_temporary_(is_temporary)
1117  , if_not_exists_(if_not_exists) {
1118  if (s) {
1119  for (const auto& e : *s) {
1120  storage_options_.emplace_back(e);
1121  }
1122  delete s;
1123  }
1124  }
InsertIntoTableAsSelectStmt(const std::string *table_name, const std::string *select_query, std::list< std::string *> *c)
Definition: ParserNode.h:1074
std::list< std::unique_ptr< NameValueAssign > > storage_options_
Definition: ParserNode.h:1131

Member Function Documentation

◆ execute()

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

Reimplemented from Parser::InsertIntoTableAsSelectStmt.

Definition at line 2859 of file ParserNode.cpp.

References Catalog_Namespace::SessionInfo::checkDBAccessPrivileges(), Data_Namespace::CPU_LEVEL, query_state::QueryState::create(), 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::LocalConnector::getColumnDescriptors(), Fragmenter_Namespace::INSERT_ORDER, TableDescriptor::isView, TableDescriptor::keyMetainfo, TableDescriptor::maxChunkSize, TableDescriptor::maxFragRows, TableDescriptor::maxRows, TableDescriptor::nColumns, TableDescriptor::persistenceLevel, Parser::LocalConnector::query(), run_benchmark_import::result, STDLOG, TableDBObjectType, TableDescriptor::tableName, TableDescriptor::userId, and Catalog_Namespace::UserMetadata::userId.

2859  {
2860  auto session_copy = session;
2861  auto session_ptr = std::shared_ptr<Catalog_Namespace::SessionInfo>(
2862  &session_copy, boost::null_deleter());
2864  auto stdlog = STDLOG(query_state);
2865 
2866  LocalConnector local_connector;
2867  auto& catalog = session.getCatalog();
2868  bool create_table = nullptr == leafs_connector_;
2869 
2870  if (create_table) {
2871  // check access privileges
2874  throw std::runtime_error("CTAS failed. Table " + table_name_ +
2875  " will not be created. User has no create privileges.");
2876  }
2877 
2878  if (catalog.getMetadataForTable(table_name_) != nullptr) {
2879  if (if_not_exists_) {
2880  return;
2881  }
2882  throw std::runtime_error("Table " + table_name_ +
2883  " already exists and no data was loaded.");
2884  }
2885 
2886  // only validate the select query so we get the target types
2887  // correctly, but do not populate the result set
2888  auto result = local_connector.query(
2889  query_state->createQueryStateProxy(), select_query_, {}, true);
2890  const auto column_descriptors_for_create =
2891  local_connector.getColumnDescriptors(result, true);
2892 
2893  // some validation as the QE might return some out of range column types
2894  for (auto& cd : column_descriptors_for_create) {
2895  if (cd.columnType.is_decimal() && cd.columnType.get_precision() > 18) {
2896  throw std::runtime_error(cd.columnName + ": Precision too high, max 18.");
2897  }
2898  }
2899 
2900  TableDescriptor td;
2901  td.tableName = table_name_;
2902  td.userId = session.get_currentUser().userId;
2903  td.nColumns = column_descriptors_for_create.size();
2904  td.isView = false;
2905  td.fragmenter = nullptr;
2911  td.keyMetainfo = "[]";
2912  if (is_temporary_) {
2914  } else {
2916  }
2917 
2918  if (!storage_options_.empty()) {
2919  for (auto& p : storage_options_) {
2920  get_table_definitions(td, p, column_descriptors_for_create);
2921  }
2922  }
2923 
2924  catalog.createTable(td, column_descriptors_for_create, {}, true);
2925  // TODO (max): It's transactionally unsafe, should be fixed: we may create object
2926  // w/o privileges
2927  SysCatalog::instance().createDBObject(
2928  session.get_currentUser(), td.tableName, TableDBObjectType, catalog);
2929  }
2930 
2931  try {
2932  populateData(query_state->createQueryStateProxy(), false);
2933  } catch (...) {
2934  if (!g_cluster) {
2935  const TableDescriptor* created_td = catalog.getMetadataForTable(table_name_);
2936  if (created_td) {
2937  catalog.dropTable(created_td);
2938  }
2939  }
2940  throw;
2941  }
2942 }
std::string tableName
void populateData(QueryStateProxy, bool validate_table)
#define DEFAULT_MAX_CHUNK_SIZE
const UserMetadata & get_currentUser() const
Definition: SessionInfo.h:68
#define DEFAULT_MAX_ROWS
std::list< std::unique_ptr< NameValueAssign > > storage_options_
Definition: ParserNode.h:1131
Catalog & getCatalog() const
Definition: SessionInfo.h:65
static std::shared_ptr< QueryState > create(ARGS &&... args)
Definition: QueryState.h:140
static const AccessPrivileges CREATE_TABLE
Definition: DBObject.h:159
std::string keyMetainfo
std::shared_ptr< Fragmenter_Namespace::AbstractFragmenter > fragmenter
#define DEFAULT_PAGE_SIZE
#define DEFAULT_FRAGMENT_ROWS
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
DistributedConnector * leafs_connector_
Definition: ParserNode.h:1096
void get_table_definitions(TableDescriptor &td, const std::unique_ptr< NameValueAssign > &p, const std::list< ColumnDescriptor > &columns)
bool g_cluster
specifies the content in-memory of a row in the table metadata table
#define STDLOG(...)
Definition: QueryState.h:225
+ 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 1130 of file ParserNode.h.

◆ is_temporary_

const bool Parser::CreateTableAsSelectStmt::is_temporary_
private

Definition at line 1129 of file ParserNode.h.

◆ storage_options_

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

Definition at line 1131 of file ParserNode.h.


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