OmniSciDB  1dac507f6e
 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 2777 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.

2777  {
2778  auto session_copy = session;
2779  auto session_ptr = std::shared_ptr<Catalog_Namespace::SessionInfo>(
2780  &session_copy, boost::null_deleter());
2781  auto query_state = query_state::QueryState::create(session_ptr, select_query_);
2782  auto stdlog = STDLOG(query_state);
2783 
2784  LocalConnector local_connector;
2785  auto& catalog = session.getCatalog();
2786  bool create_table = nullptr == leafs_connector_;
2787 
2788  if (create_table) {
2789  // check access privileges
2792  throw std::runtime_error("CTAS failed. Table " + table_name_ +
2793  " will not be created. User has no create privileges.");
2794  }
2795 
2796  if (catalog.getMetadataForTable(table_name_) != nullptr) {
2797  if (if_not_exists_) {
2798  return;
2799  }
2800  throw std::runtime_error("Table " + table_name_ +
2801  " already exists and no data was loaded.");
2802  }
2803 
2804  // only validate the select query so we get the target types
2805  // correctly, but do not populate the result set
2806  auto result =
2807  local_connector.query(query_state->createQueryStateProxy(), select_query_, true);
2808  const auto column_descriptors_for_create =
2809  local_connector.getColumnDescriptors(result, true);
2810 
2811  // some validation as the QE might return some out of range column types
2812  for (auto& cd : column_descriptors_for_create) {
2813  if (cd.columnType.is_decimal() && cd.columnType.get_precision() > 18) {
2814  throw std::runtime_error(cd.columnName + ": Precision too high, max 18.");
2815  }
2816  }
2817 
2818  TableDescriptor td;
2819  td.tableName = table_name_;
2820  td.userId = session.get_currentUser().userId;
2821  td.nColumns = column_descriptors_for_create.size();
2822  td.isView = false;
2823  td.fragmenter = nullptr;
2829  td.keyMetainfo = "[]";
2830  if (is_temporary_) {
2832  } else {
2834  }
2835 
2836  if (!storage_options_.empty()) {
2837  for (auto& p : storage_options_) {
2838  get_table_definitions(td, p, column_descriptors_for_create);
2839  }
2840  }
2841 
2842  catalog.createTable(td, column_descriptors_for_create, {}, true);
2843  // TODO (max): It's transactionally unsafe, should be fixed: we may create object
2844  // w/o privileges
2845  SysCatalog::instance().createDBObject(
2846  session.get_currentUser(), td.tableName, TableDBObjectType, catalog);
2847  }
2848 
2849  try {
2850  populateData(query_state->createQueryStateProxy(), is_temporary_, false);
2851  } catch (...) {
2852  if (!g_cluster) {
2853  const TableDescriptor* created_td = catalog.getMetadataForTable(table_name_);
2854  if (created_td) {
2855  catalog.dropTable(created_td);
2856  }
2857  }
2858  throw;
2859  }
2860 }
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: