OmniSciDB  addbbd5075
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 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 1069 of file ParserNode.h.

Constructor & Destructor Documentation

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 1071 of file ParserNode.h.

References storage_options_.

1076  : InsertIntoTableAsSelectStmt(table_name, select_query, nullptr)
1077  , is_temporary_(is_temporary)
1078  , if_not_exists_(if_not_exists) {
1079  if (s) {
1080  for (const auto& e : *s) {
1081  storage_options_.emplace_back(e);
1082  }
1083  delete s;
1084  }
1085  }
std::list< std::unique_ptr< NameValueAssign > > storage_options_
Definition: ParserNode.h:1092
InsertIntoTableAsSelectStmt(const std::string *table_name, const std::string *select_query, std::list< std::string * > *c)
Definition: ParserNode.h:1010

Member Function Documentation

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

Reimplemented from Parser::InsertIntoTableAsSelectStmt.

Definition at line 2776 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::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, STDLOG, TableDBObjectType, TableDescriptor::tableName, TableDescriptor::userId, and Catalog_Namespace::UserMetadata::userId.

2776  {
2777  auto session_copy = session;
2778  auto session_ptr = std::shared_ptr<Catalog_Namespace::SessionInfo>(
2779  &session_copy, boost::null_deleter());
2780  auto query_state = query_state::QueryState::create(session_ptr, select_query_);
2781  auto stdlog = STDLOG(query_state);
2782 
2783  LocalConnector local_connector;
2784  auto& catalog = session.getCatalog();
2785  bool create_table = nullptr == leafs_connector_;
2786 
2787  if (create_table) {
2788  // check access privileges
2791  throw std::runtime_error("CTAS failed. Table " + table_name_ +
2792  " will not be created. User has no create privileges.");
2793  }
2794 
2795  if (catalog.getMetadataForTable(table_name_) != nullptr) {
2796  if (if_not_exists_) {
2797  return;
2798  }
2799  throw std::runtime_error("Table " + table_name_ +
2800  " already exists and no data was loaded.");
2801  }
2802 
2803  // only validate the select query so we get the target types
2804  // correctly, but do not populate the result set
2805  auto result =
2806  local_connector.query(query_state->createQueryStateProxy(), select_query_, true);
2807  const auto column_descriptors_for_create =
2808  local_connector.getColumnDescriptors(result, true);
2809 
2810  // some validation as the QE might return some out of range column types
2811  for (auto& cd : column_descriptors_for_create) {
2812  if (cd.columnType.is_decimal() && cd.columnType.get_precision() > 18) {
2813  throw std::runtime_error(cd.columnName + ": Precision too high, max 18.");
2814  }
2815  }
2816 
2817  TableDescriptor td;
2818  td.tableName = table_name_;
2819  td.userId = session.get_currentUser().userId;
2820  td.nColumns = column_descriptors_for_create.size();
2821  td.isView = false;
2822  td.fragmenter = nullptr;
2828  td.keyMetainfo = "[]";
2829  if (is_temporary_) {
2831  } else {
2833  }
2834 
2835  if (!storage_options_.empty()) {
2836  for (auto& p : storage_options_) {
2837  get_table_definitions(td, p, column_descriptors_for_create);
2838  }
2839  }
2840 
2841  catalog.createTable(td, column_descriptors_for_create, {}, true);
2842  // TODO (max): It's transactionally unsafe, should be fixed: we may create object
2843  // w/o privileges
2844  SysCatalog::instance().createDBObject(
2845  session.get_currentUser(), td.tableName, TableDBObjectType, catalog);
2846  }
2847 
2848  try {
2849  populateData(query_state->createQueryStateProxy(), is_temporary_, false);
2850  } catch (...) {
2851  if (!g_cluster) {
2852  const TableDescriptor* created_td = catalog.getMetadataForTable(table_name_);
2853  if (created_td) {
2854  catalog.dropTable(created_td);
2855  }
2856  }
2857  throw;
2858  }
2859 }
std::string tableName
bool g_cluster
void populateData(QueryStateProxy, bool is_temporary, bool validate_table)
static std::shared_ptr< QueryState > create(ARGS &&...args)
Definition: QueryState.h:140
#define DEFAULT_MAX_ROWS
std::list< std::unique_ptr< NameValueAssign > > storage_options_
Definition: ParserNode.h:1092
#define DEFAULT_PAGE_SIZE
static const AccessPrivileges CREATE_TABLE
Definition: DBObject.h:151
std::string keyMetainfo
Catalog & getCatalog() const
Definition: SessionInfo.h:90
Fragmenter_Namespace::FragmenterType fragType
Data_Namespace::MemoryLevel persistenceLevel
#define DEFAULT_FRAGMENT_ROWS
DistributedConnector * leafs_connector_
Definition: ParserNode.h:1057
void get_table_definitions(TableDescriptor &td, const std::unique_ptr< NameValueAssign > &p, const std::list< ColumnDescriptor > &columns)
#define DEFAULT_MAX_CHUNK_SIZE
specifies the content in-memory of a row in the table metadata table
bool checkDBAccessPrivileges(const DBObjectType &permissionType, const AccessPrivileges &privs, const std::string &objectName="") const
Definition: SessionInfo.cpp:24
Fragmenter_Namespace::AbstractFragmenter * fragmenter
const UserMetadata & get_currentUser() const
Definition: SessionInfo.h:93
#define STDLOG(...)
Definition: QueryState.h:225

+ Here is the call graph for this function:

Member Data Documentation

const bool Parser::CreateTableAsSelectStmt::if_not_exists_
private

Definition at line 1091 of file ParserNode.h.

const bool Parser::CreateTableAsSelectStmt::is_temporary_
private

Definition at line 1090 of file ParserNode.h.

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

Definition at line 1092 of file ParserNode.h.

Referenced by CreateTableAsSelectStmt().


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