OmniSciDB  06b3bd477c
 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 1839 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 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

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

Implements Parser::DDLStmt.

Definition at line 4591 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.

4591  {
4592  auto session_copy = session;
4593  auto session_ptr = std::shared_ptr<Catalog_Namespace::SessionInfo>(
4594  &session_copy, boost::null_deleter());
4595  auto query_state = query_state::QueryState::create(session_ptr, select_query_);
4596  auto stdlog = STDLOG(query_state);
4597  auto& catalog = session.getCatalog();
4598 
4599  if (!catalog.validateNonExistentTableOrView(view_name_, if_not_exists_)) {
4600  return;
4601  }
4604  throw std::runtime_error("View " + view_name_ +
4605  " will not be created. User has no create view privileges.");
4606  }
4607 
4608  const auto query_after_shim = pg_shim(select_query_);
4609 
4610  // this now also ensures that access permissions are checked
4611  catalog.getCalciteMgr()->process(query_state->createQueryStateProxy(),
4612  query_after_shim,
4613  {},
4614  true,
4615  false,
4616  false,
4617  true);
4618 
4619  // Take write lock after the query is processed to ensure no deadlocks
4620  const auto execute_write_lock = mapd_unique_lock<mapd_shared_mutex>(
4623 
4624  TableDescriptor td;
4625  td.tableName = view_name_;
4626  td.userId = session.get_currentUser().userId;
4627  td.nColumns = 0;
4628  td.isView = true;
4629  td.viewSQL = query_after_shim;
4630  td.fragmenter = nullptr;
4632  td.maxFragRows =
4633  DEFAULT_FRAGMENT_ROWS; // @todo this stuff should not be InsertOrderFragmenter
4634  td.maxChunkSize =
4635  DEFAULT_MAX_CHUNK_SIZE; // @todo this stuff should not be InsertOrderFragmenter
4636  td.fragPageSize = DEFAULT_PAGE_SIZE;
4637  td.maxRows = DEFAULT_MAX_ROWS;
4638  catalog.createTable(td, {}, {}, true);
4639 
4640  // TODO (max): It's transactionally unsafe, should be fixed: we may create object w/o
4641  // privileges
4642  SysCatalog::instance().createDBObject(
4643  session.get_currentUser(), view_name_, ViewDBObjectType, catalog);
4644 }
std::string tableName
static std::shared_ptr< QueryState > create(ARGS &&...args)
Definition: QueryState.h:140
#define DEFAULT_MAX_CHUNK_SIZE
#define DEFAULT_MAX_ROWS
const std::string select_query_
Definition: ParserNode.h:1853
#define DEFAULT_PAGE_SIZE
const bool if_not_exists_
Definition: ParserNode.h:1854
Catalog & getCatalog() const
Definition: SessionInfo.h:65
#define DEFAULT_FRAGMENT_ROWS
const std::string view_name_
Definition: ParserNode.h:1852
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
bool checkDBAccessPrivileges(const DBObjectType &permissionType, const AccessPrivileges &privs, const std::string &objectName="") const
Definition: SessionInfo.cpp:24
const UserMetadata & get_currentUser() const
Definition: SessionInfo.h:68
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 1848 of file ParserNode.h.

References select_query_.

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

Definition at line 1847 of file ParserNode.h.

References view_name_.

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

Member Data Documentation

const bool Parser::CreateViewStmt::if_not_exists_
private

Definition at line 1854 of file ParserNode.h.

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

Definition at line 1853 of file ParserNode.h.

Referenced by get_select_query().

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

Definition at line 1852 of file ParserNode.h.

Referenced by get_view_name().


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