OmniSciDB  1dac507f6e
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Parser::CreateViewStmt Class Reference

#include <ParserNode.h>

+ Inheritance diagram for Parser::CreateViewStmt:
+ Collaboration diagram for Parser::CreateViewStmt:

Public Member Functions

 CreateViewStmt (const std::string &view_name, const std::string &select_query, const bool if_not_exists)
 
const std::string & get_view_name () const
 
const std::string & get_select_query () const
 
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

const std::string view_name_
 
const std::string select_query_
 
const bool if_not_exists_
 

Detailed Description

Definition at line 1769 of file ParserNode.h.

Constructor & Destructor Documentation

Parser::CreateViewStmt::CreateViewStmt ( const std::string &  view_name,
const std::string &  select_query,
const bool  if_not_exists 
)
inline

Definition at line 1771 of file ParserNode.h.

1774  : view_name_(view_name)
1775  , select_query_(select_query)
1776  , if_not_exists_(if_not_exists) {}
const std::string select_query_
Definition: ParserNode.h:1783
const bool if_not_exists_
Definition: ParserNode.h:1784
const std::string view_name_
Definition: ParserNode.h:1782

Member Function Documentation

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

Implements Parser::DDLStmt.

Definition at line 4383 of file ParserNode.cpp.

References Catalog_Namespace::SessionInfo::checkDBAccessPrivileges(), query_state::QueryState::create(), AccessPrivileges::CREATE_VIEW, DEFAULT_FRAGMENT_ROWS, DEFAULT_MAX_CHUNK_SIZE, DEFAULT_MAX_ROWS, DEFAULT_PAGE_SIZE, TableDescriptor::fragmenter, TableDescriptor::fragPageSize, TableDescriptor::fragType, Catalog_Namespace::SessionInfo::get_currentUser(), Catalog_Namespace::SessionInfo::getCatalog(), Fragmenter_Namespace::INSERT_ORDER, TableDescriptor::isView, TableDescriptor::maxChunkSize, TableDescriptor::maxFragRows, TableDescriptor::maxRows, TableDescriptor::nColumns, pg_shim(), STDLOG, TableDescriptor::tableName, TableDescriptor::userId, Catalog_Namespace::UserMetadata::userId, ViewDBObjectType, and TableDescriptor::viewSQL.

4383  {
4384  auto session_copy = session;
4385  auto session_ptr = std::shared_ptr<Catalog_Namespace::SessionInfo>(
4386  &session_copy, boost::null_deleter());
4387  auto query_state = query_state::QueryState::create(session_ptr, select_query_);
4388  auto stdlog = STDLOG(query_state);
4389  auto& catalog = session.getCatalog();
4390 
4391  if (catalog.getMetadataForTable(view_name_) != nullptr) {
4392  if (if_not_exists_) {
4393  return;
4394  }
4395  throw std::runtime_error("Table or View " + view_name_ + " already exists.");
4396  }
4397 
4400  throw std::runtime_error("View " + view_name_ +
4401  " will not be created. User has no create view privileges.");
4402  }
4403 
4404  const auto query_after_shim = pg_shim(select_query_);
4405 
4406  // this now also ensures that access permissions are checked
4407  catalog.getCalciteMgr()->process(
4408  query_state->createQueryStateProxy(), query_after_shim, {}, true, false, false);
4409  TableDescriptor td;
4410  td.tableName = view_name_;
4411  td.userId = session.get_currentUser().userId;
4412  td.nColumns = 0;
4413  td.isView = true;
4414  td.viewSQL = query_after_shim;
4415  td.fragmenter = nullptr;
4417  td.maxFragRows =
4418  DEFAULT_FRAGMENT_ROWS; // @todo this stuff should not be InsertOrderFragmenter
4419  td.maxChunkSize =
4420  DEFAULT_MAX_CHUNK_SIZE; // @todo this stuff should not be InsertOrderFragmenter
4423  catalog.createTable(td, {}, {}, true);
4424 
4425  // TODO (max): It's transactionally unsafe, should be fixed: we may create object w/o
4426  // privileges
4427  SysCatalog::instance().createDBObject(
4428  session.get_currentUser(), view_name_, ViewDBObjectType, catalog);
4429 }
std::string tableName
static std::shared_ptr< QueryState > create(ARGS &&...args)
Definition: QueryState.h:140
#define DEFAULT_MAX_ROWS
#define DEFAULT_PAGE_SIZE
const std::string select_query_
Definition: ParserNode.h:1783
const bool if_not_exists_
Definition: ParserNode.h:1784
Catalog & getCatalog() const
Definition: SessionInfo.h:90
const std::string view_name_
Definition: ParserNode.h:1782
Fragmenter_Namespace::FragmenterType fragType
#define DEFAULT_FRAGMENT_ROWS
static const AccessPrivileges CREATE_VIEW
Definition: DBObject.h:171
#define DEFAULT_MAX_CHUNK_SIZE
std::string viewSQL
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
std::string pg_shim(const std::string &query)
#define STDLOG(...)
Definition: QueryState.h:225

+ Here is the call graph for this function:

const std::string& Parser::CreateViewStmt::get_select_query ( ) const
inline

Definition at line 1778 of file ParserNode.h.

References select_query_.

1778 { return select_query_; }
const std::string select_query_
Definition: ParserNode.h:1783
const std::string& Parser::CreateViewStmt::get_view_name ( ) const
inline

Definition at line 1777 of file ParserNode.h.

References view_name_.

1777 { return view_name_; }
const std::string view_name_
Definition: ParserNode.h:1782

Member Data Documentation

const bool Parser::CreateViewStmt::if_not_exists_
private

Definition at line 1784 of file ParserNode.h.

const std::string Parser::CreateViewStmt::select_query_
private

Definition at line 1783 of file ParserNode.h.

Referenced by get_select_query().

const std::string Parser::CreateViewStmt::view_name_
private

Definition at line 1782 of file ParserNode.h.

Referenced by get_view_name().


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