OmniSciDB  c1a53651b2
 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, bool read_only_mode) 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 1883 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 1885 of file ParserNode.h.

1888  : view_name_(view_name)
1889  , select_query_(select_query)
1890  , if_not_exists_(if_not_exists) {}
std::string select_query_
Definition: ParserNode.h:1901
std::string view_name_
Definition: ParserNode.h:1900
Parser::CreateViewStmt::CreateViewStmt ( const rapidjson::Value &  payload)

Definition at line 6404 of file ParserNode.cpp.

References CHECK, if_not_exists_, json_bool(), json_str(), select_query_, and view_name_.

6404  {
6405  CHECK(payload.HasMember("name"));
6406  view_name_ = json_str(payload["name"]);
6407 
6408  if_not_exists_ = false;
6409  if (payload.HasMember("ifNotExists")) {
6410  if_not_exists_ = json_bool(payload["ifNotExists"]);
6411  }
6412 
6413  CHECK(payload.HasMember("query"));
6414  select_query_ = json_str(payload["query"]);
6415  std::regex newline_re("\\n");
6416  select_query_ = std::regex_replace(select_query_, newline_re, " ");
6417  // ensure a trailing semicolon is present on the select query
6418  if (select_query_.back() != ';') {
6419  select_query_.push_back(';');
6420  }
6421 }
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:1901
#define CHECK(condition)
Definition: Logger.h:291
std::string view_name_
Definition: ParserNode.h:1900

+ Here is the call graph for this function:

Member Function Documentation

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

Implements Parser::DDLStmt.

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

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

6424  {
6425  if (read_only_mode) {
6426  throw std::runtime_error("CREATE VIEW invalid in read only mode.");
6427  }
6428  auto session_copy = session;
6429  auto session_ptr = std::shared_ptr<Catalog_Namespace::SessionInfo>(
6430  &session_copy, boost::null_deleter());
6431  auto query_state = query_state::QueryState::create(session_ptr, select_query_);
6432  auto stdlog = STDLOG(query_state);
6433  auto& catalog = session.getCatalog();
6434 
6435  if (!catalog.validateNonExistentTableOrView(view_name_, if_not_exists_)) {
6436  return;
6437  }
6440  throw std::runtime_error("View " + view_name_ +
6441  " will not be created. User has no create view privileges.");
6442  }
6443 
6444  const auto query_after_shim = pg_shim(select_query_);
6445  auto calcite_mgr = catalog.getCalciteMgr();
6446 
6447  // this now also ensures that access permissions are checked
6448  const auto calciteQueryParsingOption =
6449  calcite_mgr->getCalciteQueryParsingOption(true, false, true);
6450  const auto calciteOptimizationOption = calcite_mgr->getCalciteOptimizationOption(
6451  false, g_enable_watchdog, {}, SysCatalog::instance().isAggregator());
6452  calcite_mgr->process(query_state->createQueryStateProxy(),
6453  query_after_shim,
6454  calciteQueryParsingOption,
6455  calciteOptimizationOption);
6456 
6457  // Take write lock after the query is processed to ensure no deadlocks
6458  const auto execute_write_lock =
6462 
6463  TableDescriptor td;
6464  td.tableName = view_name_;
6465  td.userId = session.get_currentUser().userId;
6466  td.nColumns = 0;
6467  td.isView = true;
6468  td.viewSQL = query_after_shim;
6469  td.fragmenter = nullptr;
6471  td.maxFragRows = DEFAULT_FRAGMENT_ROWS; // @todo this stuff should not be
6472  // InsertOrderFragmenter
6473  td.maxChunkSize = DEFAULT_MAX_CHUNK_SIZE; // @todo this stuff should not be
6474  // InsertOrderFragmenter
6475  td.fragPageSize = DEFAULT_PAGE_SIZE;
6476  td.maxRows = DEFAULT_MAX_ROWS;
6477  catalog.createTable(td, {}, {}, true);
6478 
6479  // TODO (max): It's transactionally unsafe, should be fixed: we may create
6480  // object w/o privileges
6481  SysCatalog::instance().createDBObject(
6482  session.get_currentUser(), view_name_, ViewDBObjectType, catalog);
6483 }
static std::shared_ptr< WrapperType< MutexType > > getMutex(const LockType lockType, const KeyType &key)
std::string tableName
static std::shared_ptr< QueryState > create(ARGS &&...args)
Definition: QueryState.h:148
#define DEFAULT_MAX_CHUNK_SIZE
#define DEFAULT_MAX_ROWS
std::unique_lock< T > unique_lock
std::string select_query_
Definition: ParserNode.h:1901
bool g_enable_watchdog
#define DEFAULT_PAGE_SIZE
Catalog & getCatalog() const
Definition: SessionInfo.h:75
#define DEFAULT_FRAGMENT_ROWS
static const AccessPrivileges CREATE_VIEW
Definition: DBObject.h:178
bool checkDBAccessPrivileges(const DBObjectType &permissionType, const AccessPrivileges &privs, const std::string &objectName="") const
Definition: SessionInfo.cpp:24
std::string view_name_
Definition: ParserNode.h:1900
const UserMetadata & get_currentUser() const
Definition: SessionInfo.h:88
std::string pg_shim(const std::string &query)
#define STDLOG(...)
Definition: QueryState.h:234

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

References select_query_.

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

Definition at line 1894 of file ParserNode.h.

References view_name_.

1894 { return view_name_; }
std::string view_name_
Definition: ParserNode.h:1900

Member Data Documentation

bool Parser::CreateViewStmt::if_not_exists_
private

Definition at line 1902 of file ParserNode.h.

Referenced by CreateViewStmt(), and execute().

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

Definition at line 1901 of file ParserNode.h.

Referenced by CreateViewStmt(), execute(), and get_select_query().

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

Definition at line 1900 of file ParserNode.h.

Referenced by CreateViewStmt(), execute(), and get_view_name().


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