OmniSciDB  04ee39c94c
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 1668 of file ParserNode.h.

Constructor & Destructor Documentation

◆ CreateViewStmt()

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

Definition at line 1670 of file ParserNode.h.

1673  : view_name_(view_name)
1674  , select_query_(select_query)
1675  , if_not_exists_(if_not_exists) {}
const std::string select_query_
Definition: ParserNode.h:1682
const bool if_not_exists_
Definition: ParserNode.h:1683
const std::string view_name_
Definition: ParserNode.h:1681

Member Function Documentation

◆ execute()

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

Implements Parser::DDLStmt.

Definition at line 4324 of file ParserNode.cpp.

References Catalog_Namespace::SessionInfo::checkDBAccessPrivileges(), 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(), TableDescriptor::tableName, TableDescriptor::userId, Catalog_Namespace::UserMetadata::userId, ViewDBObjectType, and TableDescriptor::viewSQL.

4324  {
4325  auto& catalog = session.getCatalog();
4326 
4327  if (catalog.getMetadataForTable(view_name_) != nullptr) {
4328  if (if_not_exists_) {
4329  return;
4330  }
4331  throw std::runtime_error("Table or View " + view_name_ + " already exists.");
4332  }
4333 
4336  throw std::runtime_error("View " + view_name_ +
4337  " will not be created. User has no create view privileges.");
4338  }
4339 
4340  const auto query_after_shim = pg_shim(select_query_);
4341 
4342  // this now also ensures that access permissions are checked
4343  catalog.getCalciteMgr()->process(session, query_after_shim, {}, true, false, false);
4344  TableDescriptor td;
4345  td.tableName = view_name_;
4346  td.userId = session.get_currentUser().userId;
4347  td.nColumns = 0;
4348  td.isView = true;
4349  td.viewSQL = query_after_shim;
4350  td.fragmenter = nullptr;
4352  td.maxFragRows =
4353  DEFAULT_FRAGMENT_ROWS; // @todo this stuff should not be InsertOrderFragmenter
4354  td.maxChunkSize =
4355  DEFAULT_MAX_CHUNK_SIZE; // @todo this stuff should not be InsertOrderFragmenter
4358  catalog.createTable(td, {}, {}, true);
4359 
4360  // TODO (max): It's transactionally unsafe, should be fixed: we may create object w/o
4361  // privileges
4362  SysCatalog::instance().createDBObject(
4363  session.get_currentUser(), view_name_, ViewDBObjectType, catalog);
4364 }
std::string tableName
#define DEFAULT_MAX_ROWS
const UserMetadata & get_currentUser() const
Definition: SessionInfo.h:93
Catalog & getCatalog() const
Definition: SessionInfo.h:90
#define DEFAULT_PAGE_SIZE
const std::string select_query_
Definition: ParserNode.h:1682
const bool if_not_exists_
Definition: ParserNode.h:1683
const std::string view_name_
Definition: ParserNode.h:1681
Fragmenter_Namespace::FragmenterType fragType
bool checkDBAccessPrivileges(const DBObjectType &permissionType, const AccessPrivileges &privs, const std::string &objectName="") const
Definition: SessionInfo.cpp:24
#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
Fragmenter_Namespace::AbstractFragmenter * fragmenter
std::string pg_shim(const std::string &query)
+ Here is the call graph for this function:

◆ get_select_query()

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

Definition at line 1677 of file ParserNode.h.

References session.

1677 { return select_query_; }
const std::string select_query_
Definition: ParserNode.h:1682

◆ get_view_name()

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

Definition at line 1676 of file ParserNode.h.

1676 { return view_name_; }
const std::string view_name_
Definition: ParserNode.h:1681

Member Data Documentation

◆ if_not_exists_

const bool Parser::CreateViewStmt::if_not_exists_
private

Definition at line 1683 of file ParserNode.h.

◆ select_query_

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

Definition at line 1682 of file ParserNode.h.

◆ view_name_

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

Definition at line 1681 of file ParserNode.h.


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