OmniSciDB  eb3a3d0a03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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)
 
 CreateViewStmt (const rapidjson::Value &payload)
 
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

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

Detailed Description

Definition at line 1888 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 1890 of file ParserNode.h.

1893  : view_name_(view_name)
1894  , select_query_(select_query)
1895  , if_not_exists_(if_not_exists) {}
std::string select_query_
Definition: ParserNode.h:1905
std::string view_name_
Definition: ParserNode.h:1904
Parser::CreateViewStmt::CreateViewStmt ( const rapidjson::Value &  payload)

Definition at line 5856 of file ParserNode.cpp.

References CHECK, json_bool(), and json_str().

5856  {
5857  CHECK(payload.HasMember("name"));
5858  view_name_ = json_str(payload["name"]);
5859 
5860  if_not_exists_ = false;
5861  if (payload.HasMember("ifNotExists")) {
5862  if_not_exists_ = json_bool(payload["ifNotExists"]);
5863  }
5864 
5865  CHECK(payload.HasMember("query"));
5866  select_query_ = json_str(payload["query"]);
5867  std::regex newline_re("\\n");
5868  select_query_ = std::regex_replace(select_query_, newline_re, " ");
5869  // ensure a trailing semicolon is present on the select query
5870  if (select_query_.back() != ';') {
5871  select_query_.push_back(';');
5872  }
5873 }
const bool json_bool(const rapidjson::Value &obj) noexcept
Definition: JsonAccessors.h:49
const std::string json_str(const rapidjson::Value &obj) noexcept
Definition: JsonAccessors.h:44
std::string select_query_
Definition: ParserNode.h:1905
#define CHECK(condition)
Definition: Logger.h:209
std::string view_name_
Definition: ParserNode.h:1904

+ Here is the call graph for this function:

Member Function Documentation

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

Implements Parser::DDLStmt.

Definition at line 5875 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().

5875  {
5876  auto session_copy = session;
5877  auto session_ptr = std::shared_ptr<Catalog_Namespace::SessionInfo>(
5878  &session_copy, boost::null_deleter());
5879  auto query_state = query_state::QueryState::create(session_ptr, select_query_);
5880  auto stdlog = STDLOG(query_state);
5881  auto& catalog = session.getCatalog();
5882 
5883  if (!catalog.validateNonExistentTableOrView(view_name_, if_not_exists_)) {
5884  return;
5885  }
5888  throw std::runtime_error("View " + view_name_ +
5889  " will not be created. User has no create view privileges.");
5890  }
5891 
5892  const auto query_after_shim = pg_shim(select_query_);
5893 
5894  // this now also ensures that access permissions are checked
5895  catalog.getCalciteMgr()->process(query_state->createQueryStateProxy(),
5896  query_after_shim,
5897  {},
5898  true,
5899  false,
5900  false,
5901  true);
5902 
5903  // Take write lock after the query is processed to ensure no deadlocks
5904  const auto execute_write_lock = mapd_unique_lock<mapd_shared_mutex>(
5907 
5908  TableDescriptor td;
5909  td.tableName = view_name_;
5910  td.userId = session.get_currentUser().userId;
5911  td.nColumns = 0;
5912  td.isView = true;
5913  td.viewSQL = query_after_shim;
5914  td.fragmenter = nullptr;
5916  td.maxFragRows = DEFAULT_FRAGMENT_ROWS; // @todo this stuff should not be
5917  // InsertOrderFragmenter
5918  td.maxChunkSize = DEFAULT_MAX_CHUNK_SIZE; // @todo this stuff should not be
5919  // InsertOrderFragmenter
5920  td.fragPageSize = DEFAULT_PAGE_SIZE;
5921  td.maxRows = DEFAULT_MAX_ROWS;
5922  catalog.createTable(td, {}, {}, true);
5923 
5924  // TODO (max): It's transactionally unsafe, should be fixed: we may create
5925  // object w/o privileges
5926  SysCatalog::instance().createDBObject(
5927  session.get_currentUser(), view_name_, ViewDBObjectType, catalog);
5928 }
std::string tableName
static std::shared_ptr< QueryState > create(ARGS &&...args)
Definition: QueryState.h:145
#define DEFAULT_MAX_CHUNK_SIZE
#define DEFAULT_MAX_ROWS
std::string select_query_
Definition: ParserNode.h:1905
#define DEFAULT_PAGE_SIZE
Catalog & getCatalog() const
Definition: SessionInfo.h:67
#define DEFAULT_FRAGMENT_ROWS
static std::shared_ptr< MutexType > getMutex(const LockType lockType, const KeyType &key)
Definition: LegacyLockMgr.h:51
static const AccessPrivileges CREATE_VIEW
Definition: DBObject.h:180
bool checkDBAccessPrivileges(const DBObjectType &permissionType, const AccessPrivileges &privs, const std::string &objectName="") const
Definition: SessionInfo.cpp:24
std::string view_name_
Definition: ParserNode.h:1904
const UserMetadata & get_currentUser() const
Definition: SessionInfo.h:73
std::string pg_shim(const std::string &query)
#define STDLOG(...)
Definition: QueryState.h:235

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 1900 of file ParserNode.h.

References select_query_.

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

Definition at line 1899 of file ParserNode.h.

References view_name_.

1899 { return view_name_; }
std::string view_name_
Definition: ParserNode.h:1904

Member Data Documentation

bool Parser::CreateViewStmt::if_not_exists_
private

Definition at line 1906 of file ParserNode.h.

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

Definition at line 1905 of file ParserNode.h.

Referenced by get_select_query().

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

Definition at line 1904 of file ParserNode.h.

Referenced by get_view_name().


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