OmniSciDB  cde582ebc3
 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 1927 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 1929 of file ParserNode.h.

1932  : view_name_(view_name)
1933  , select_query_(select_query)
1934  , if_not_exists_(if_not_exists) {}
std::string select_query_
Definition: ParserNode.h:1945
std::string view_name_
Definition: ParserNode.h:1944
Parser::CreateViewStmt::CreateViewStmt ( const rapidjson::Value &  payload)

Definition at line 6327 of file ParserNode.cpp.

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

6327  {
6328  CHECK(payload.HasMember("name"));
6329  view_name_ = json_str(payload["name"]);
6330 
6331  if_not_exists_ = false;
6332  if (payload.HasMember("ifNotExists")) {
6333  if_not_exists_ = json_bool(payload["ifNotExists"]);
6334  }
6335 
6336  CHECK(payload.HasMember("query"));
6337  select_query_ = json_str(payload["query"]);
6338  std::regex newline_re("\\n");
6339  select_query_ = std::regex_replace(select_query_, newline_re, " ");
6340  // ensure a trailing semicolon is present on the select query
6341  if (select_query_.back() != ';') {
6342  select_query_.push_back(';');
6343  }
6344 }
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:1945
#define CHECK(condition)
Definition: Logger.h:222
std::string view_name_
Definition: ParserNode.h:1944

+ 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 6346 of file ParserNode.cpp.

References Catalog_Namespace::SessionInfo::checkDBAccessPrivileges(), query_state::QueryState::create(), AccessPrivileges::CREATE_VIEW, Catalog_Namespace::Catalog::createTable(), 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::Catalog::getCalciteMgr(), 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, Catalog_Namespace::Catalog::validateNonExistentTableOrView(), view_name_, and ViewDBObjectType.

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

6347  {
6348  if (read_only_mode) {
6349  throw std::runtime_error("CREATE VIEW invalid in read only mode.");
6350  }
6351  auto session_copy = session;
6352  auto session_ptr = std::shared_ptr<Catalog_Namespace::SessionInfo>(
6353  &session_copy, boost::null_deleter());
6354  auto query_state = query_state::QueryState::create(session_ptr, select_query_);
6355  auto stdlog = STDLOG(query_state);
6356  auto& catalog = session.getCatalog();
6357 
6358  if (!catalog.validateNonExistentTableOrView(view_name_, if_not_exists_)) {
6359  return;
6360  }
6363  throw std::runtime_error("View " + view_name_ +
6364  " will not be created. User has no create view privileges.");
6365  }
6366 
6367  const auto query_after_shim = pg_shim(select_query_);
6368  auto calcite_mgr = catalog.getCalciteMgr();
6369 
6370  // this now also ensures that access permissions are checked
6371  const auto calciteQueryParsingOption =
6372  calcite_mgr->getCalciteQueryParsingOption(true, false, true);
6373  const auto calciteOptimizationOption =
6374  calcite_mgr->getCalciteOptimizationOption(false, g_enable_watchdog, {});
6375  calcite_mgr->process(query_state->createQueryStateProxy(),
6376  query_after_shim,
6377  calciteQueryParsingOption,
6378  calciteOptimizationOption);
6379 
6380  // Take write lock after the query is processed to ensure no deadlocks
6381  const auto execute_write_lock =
6385 
6386  TableDescriptor td;
6387  td.tableName = view_name_;
6388  td.userId = session.get_currentUser().userId;
6389  td.nColumns = 0;
6390  td.isView = true;
6391  td.viewSQL = query_after_shim;
6392  td.fragmenter = nullptr;
6394  td.maxFragRows = DEFAULT_FRAGMENT_ROWS; // @todo this stuff should not be
6395  // InsertOrderFragmenter
6396  td.maxChunkSize = DEFAULT_MAX_CHUNK_SIZE; // @todo this stuff should not be
6397  // InsertOrderFragmenter
6398  td.fragPageSize = DEFAULT_PAGE_SIZE;
6399  td.maxRows = DEFAULT_MAX_ROWS;
6400  catalog.createTable(td, {}, {}, true);
6401 
6402  // TODO (max): It's transactionally unsafe, should be fixed: we may create
6403  // object w/o privileges
6404  SysCatalog::instance().createDBObject(
6405  session.get_currentUser(), view_name_, ViewDBObjectType, catalog);
6406 }
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:145
#define DEFAULT_MAX_CHUNK_SIZE
#define DEFAULT_MAX_ROWS
std::unique_lock< T > unique_lock
std::string select_query_
Definition: ParserNode.h:1945
bool g_enable_watchdog
#define DEFAULT_PAGE_SIZE
Catalog & getCatalog() const
Definition: SessionInfo.h:65
#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:1944
const UserMetadata & get_currentUser() const
Definition: SessionInfo.h:71
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 1939 of file ParserNode.h.

References select_query_.

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

Definition at line 1938 of file ParserNode.h.

References view_name_.

1938 { return view_name_; }
std::string view_name_
Definition: ParserNode.h:1944

Member Data Documentation

bool Parser::CreateViewStmt::if_not_exists_
private

Definition at line 1946 of file ParserNode.h.

Referenced by CreateViewStmt(), and execute().

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

Definition at line 1945 of file ParserNode.h.

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

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

Definition at line 1944 of file ParserNode.h.

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


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