OmniSciDB  dfae7c3b14
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 1839 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 1841 of file ParserNode.h.

1844  : view_name_(view_name)
1845  , select_query_(select_query)
1846  , if_not_exists_(if_not_exists) {}
const std::string select_query_
Definition: ParserNode.h:1853
const bool if_not_exists_
Definition: ParserNode.h:1854
const std::string view_name_
Definition: ParserNode.h:1852

Member Function Documentation

◆ execute()

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

Implements Parser::DDLStmt.

Definition at line 4583 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, legacylockmgr::ExecutorOuterLock, Catalog_Namespace::SessionInfo::get_currentUser(), Catalog_Namespace::SessionInfo::getCatalog(), legacylockmgr::LockMgr< MutexType, KeyType >::getMutex(), Fragmenter_Namespace::INSERT_ORDER, pg_shim(), STDLOG, TableDescriptor::tableName, Catalog_Namespace::UserMetadata::userId, and ViewDBObjectType.

Referenced by omnisci.cursor.Cursor::executemany().

4583  {
4584  auto session_copy = session;
4585  auto session_ptr = std::shared_ptr<Catalog_Namespace::SessionInfo>(
4586  &session_copy, boost::null_deleter());
4588  auto stdlog = STDLOG(query_state);
4589  auto& catalog = session.getCatalog();
4590 
4591  if (!catalog.validateNonExistentTableOrView(view_name_, if_not_exists_)) {
4592  return;
4593  }
4596  throw std::runtime_error("View " + view_name_ +
4597  " will not be created. User has no create view privileges.");
4598  }
4599 
4600  const auto query_after_shim = pg_shim(select_query_);
4601 
4602  // this now also ensures that access permissions are checked
4603  catalog.getCalciteMgr()->process(query_state->createQueryStateProxy(),
4604  query_after_shim,
4605  {},
4606  true,
4607  false,
4608  false,
4609  true);
4610 
4611  // Take write lock after the query is processed to ensure no deadlocks
4612  const auto execute_write_lock = mapd_unique_lock<mapd_shared_mutex>(
4615 
4616  TableDescriptor td;
4617  td.tableName = view_name_;
4618  td.userId = session.get_currentUser().userId;
4619  td.nColumns = 0;
4620  td.isView = true;
4621  td.viewSQL = query_after_shim;
4622  td.fragmenter = nullptr;
4624  td.maxFragRows =
4625  DEFAULT_FRAGMENT_ROWS; // @todo this stuff should not be InsertOrderFragmenter
4626  td.maxChunkSize =
4627  DEFAULT_MAX_CHUNK_SIZE; // @todo this stuff should not be InsertOrderFragmenter
4628  td.fragPageSize = DEFAULT_PAGE_SIZE;
4629  td.maxRows = DEFAULT_MAX_ROWS;
4630  catalog.createTable(td, {}, {}, true);
4631 
4632  // TODO (max): It's transactionally unsafe, should be fixed: we may create object w/o
4633  // privileges
4634  SysCatalog::instance().createDBObject(
4635  session.get_currentUser(), view_name_, ViewDBObjectType, catalog);
4636 }
std::string tableName
#define DEFAULT_MAX_CHUNK_SIZE
const UserMetadata & get_currentUser() const
Definition: SessionInfo.h:68
#define DEFAULT_MAX_ROWS
Catalog & getCatalog() const
Definition: SessionInfo.h:65
static std::shared_ptr< QueryState > create(ARGS &&... args)
Definition: QueryState.h:140
const std::string select_query_
Definition: ParserNode.h:1853
#define DEFAULT_PAGE_SIZE
const bool if_not_exists_
Definition: ParserNode.h:1854
#define DEFAULT_FRAGMENT_ROWS
const std::string view_name_
Definition: ParserNode.h:1852
bool checkDBAccessPrivileges(const DBObjectType &permissionType, const AccessPrivileges &privs, const std::string &objectName="") const
Definition: SessionInfo.cpp:24
static std::shared_ptr< MutexType > getMutex(const LockType lockType, const KeyType &key)
Definition: LegacyLockMgr.h:51
static const AccessPrivileges CREATE_VIEW
Definition: DBObject.h:179
specifies the content in-memory of a row in the table metadata table
std::string pg_shim(const std::string &query)
#define STDLOG(...)
Definition: QueryState.h:225
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_select_query()

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

Definition at line 1848 of file ParserNode.h.

1848 { return select_query_; }
const std::string select_query_
Definition: ParserNode.h:1853

◆ get_view_name()

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

Definition at line 1847 of file ParserNode.h.

1847 { return view_name_; }
const std::string view_name_
Definition: ParserNode.h:1852

Member Data Documentation

◆ if_not_exists_

const bool Parser::CreateViewStmt::if_not_exists_
private

Definition at line 1854 of file ParserNode.h.

◆ select_query_

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

Definition at line 1853 of file ParserNode.h.

◆ view_name_

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

Definition at line 1852 of file ParserNode.h.


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