OmniSciDB  ba1bac9284
 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)
 
 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 1893 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 1895 of file ParserNode.h.

1898  : view_name_(view_name)
1899  , select_query_(select_query)
1900  , if_not_exists_(if_not_exists) {}
std::string select_query_
Definition: ParserNode.h:1910
std::string view_name_
Definition: ParserNode.h:1909
Parser::CreateViewStmt::CreateViewStmt ( const rapidjson::Value &  payload)

Definition at line 5507 of file ParserNode.cpp.

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

5507  {
5508  CHECK(payload.HasMember("name"));
5509  view_name_ = json_str(payload["name"]);
5510 
5511  if_not_exists_ = false;
5512  if (payload.HasMember("ifNotExists")) {
5513  if_not_exists_ = json_bool(payload["ifNotExists"]);
5514  }
5515 
5516  CHECK(payload.HasMember("query"));
5517  select_query_ = json_str(payload["query"]);
5518  std::regex newline_re("\\n");
5519  select_query_ = std::regex_replace(select_query_, newline_re, " ");
5520  // ensure a trailing semicolon is present on the select query
5521  if (select_query_.back() != ';') {
5522  select_query_.push_back(';');
5523  }
5524 }
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:1910
#define CHECK(condition)
Definition: Logger.h:206
std::string view_name_
Definition: ParserNode.h:1909

+ 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 5526 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().

5526  {
5527  auto session_copy = session;
5528  auto session_ptr = std::shared_ptr<Catalog_Namespace::SessionInfo>(
5529  &session_copy, boost::null_deleter());
5530  auto query_state = query_state::QueryState::create(session_ptr, select_query_);
5531  auto stdlog = STDLOG(query_state);
5532  auto& catalog = session.getCatalog();
5533 
5534  if (!catalog.validateNonExistentTableOrView(view_name_, if_not_exists_)) {
5535  return;
5536  }
5539  throw std::runtime_error("View " + view_name_ +
5540  " will not be created. User has no create view privileges.");
5541  }
5542 
5543  const auto query_after_shim = pg_shim(select_query_);
5544 
5545  // this now also ensures that access permissions are checked
5546  catalog.getCalciteMgr()->process(query_state->createQueryStateProxy(),
5547  query_after_shim,
5548  {},
5549  true,
5550  false,
5551  false,
5552  true);
5553 
5554  // Take write lock after the query is processed to ensure no deadlocks
5555  const auto execute_write_lock = mapd_unique_lock<mapd_shared_mutex>(
5558 
5559  TableDescriptor td;
5560  td.tableName = view_name_;
5561  td.userId = session.get_currentUser().userId;
5562  td.nColumns = 0;
5563  td.isView = true;
5564  td.viewSQL = query_after_shim;
5565  td.fragmenter = nullptr;
5567  td.maxFragRows =
5568  DEFAULT_FRAGMENT_ROWS; // @todo this stuff should not be InsertOrderFragmenter
5569  td.maxChunkSize =
5570  DEFAULT_MAX_CHUNK_SIZE; // @todo this stuff should not be InsertOrderFragmenter
5571  td.fragPageSize = DEFAULT_PAGE_SIZE;
5572  td.maxRows = DEFAULT_MAX_ROWS;
5573  catalog.createTable(td, {}, {}, true);
5574 
5575  // TODO (max): It's transactionally unsafe, should be fixed: we may create object
5576  // w/o privileges
5577  SysCatalog::instance().createDBObject(
5578  session.get_currentUser(), view_name_, ViewDBObjectType, catalog);
5579 }
std::string tableName
static std::shared_ptr< QueryState > create(ARGS &&...args)
Definition: QueryState.h:141
#define DEFAULT_MAX_CHUNK_SIZE
#define DEFAULT_MAX_ROWS
std::string select_query_
Definition: ParserNode.h:1910
#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:1909
const UserMetadata & get_currentUser() const
Definition: SessionInfo.h:73
std::string pg_shim(const std::string &query)
#define STDLOG(...)
Definition: QueryState.h:229

+ 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 1905 of file ParserNode.h.

References select_query_.

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

Definition at line 1904 of file ParserNode.h.

References view_name_.

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

Member Data Documentation

bool Parser::CreateViewStmt::if_not_exists_
private

Definition at line 1911 of file ParserNode.h.

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

Definition at line 1910 of file ParserNode.h.

Referenced by get_select_query().

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

Definition at line 1909 of file ParserNode.h.

Referenced by get_view_name().


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