OmniSciDB  c0231cc57d
 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 6377 of file ParserNode.cpp.

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

6377  {
6378  CHECK(payload.HasMember("name"));
6379  view_name_ = json_str(payload["name"]);
6380 
6381  if_not_exists_ = false;
6382  if (payload.HasMember("ifNotExists")) {
6383  if_not_exists_ = json_bool(payload["ifNotExists"]);
6384  }
6385 
6386  CHECK(payload.HasMember("query"));
6387  select_query_ = json_str(payload["query"]);
6388  std::regex newline_re("\\n");
6389  select_query_ = std::regex_replace(select_query_, newline_re, " ");
6390  // ensure a trailing semicolon is present on the select query
6391  if (select_query_.back() != ';') {
6392  select_query_.push_back(';');
6393  }
6394 }
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 6396 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().

6397  {
6398  if (read_only_mode) {
6399  throw std::runtime_error("CREATE VIEW invalid in read only mode.");
6400  }
6401  auto session_copy = session;
6402  auto session_ptr = std::shared_ptr<Catalog_Namespace::SessionInfo>(
6403  &session_copy, boost::null_deleter());
6404  auto query_state = query_state::QueryState::create(session_ptr, select_query_);
6405  auto stdlog = STDLOG(query_state);
6406  auto& catalog = session.getCatalog();
6407 
6408  if (!catalog.validateNonExistentTableOrView(view_name_, if_not_exists_)) {
6409  return;
6410  }
6413  throw std::runtime_error("View " + view_name_ +
6414  " will not be created. User has no create view privileges.");
6415  }
6416 
6417  const auto query_after_shim = pg_shim(select_query_);
6418  auto calcite_mgr = catalog.getCalciteMgr();
6419 
6420  // this now also ensures that access permissions are checked
6421  const auto calciteQueryParsingOption =
6422  calcite_mgr->getCalciteQueryParsingOption(true, false, true);
6423  const auto calciteOptimizationOption = calcite_mgr->getCalciteOptimizationOption(
6424  false, g_enable_watchdog, {}, SysCatalog::instance().isAggregator());
6425  calcite_mgr->process(query_state->createQueryStateProxy(),
6426  query_after_shim,
6427  calciteQueryParsingOption,
6428  calciteOptimizationOption);
6429 
6430  // Take write lock after the query is processed to ensure no deadlocks
6431  const auto execute_write_lock =
6435 
6436  TableDescriptor td;
6437  td.tableName = view_name_;
6438  td.userId = session.get_currentUser().userId;
6439  td.nColumns = 0;
6440  td.isView = true;
6441  td.viewSQL = query_after_shim;
6442  td.fragmenter = nullptr;
6444  td.maxFragRows = DEFAULT_FRAGMENT_ROWS; // @todo this stuff should not be
6445  // InsertOrderFragmenter
6446  td.maxChunkSize = DEFAULT_MAX_CHUNK_SIZE; // @todo this stuff should not be
6447  // InsertOrderFragmenter
6448  td.fragPageSize = DEFAULT_PAGE_SIZE;
6449  td.maxRows = DEFAULT_MAX_ROWS;
6450  catalog.createTable(td, {}, {}, true);
6451 
6452  // TODO (max): It's transactionally unsafe, should be fixed: we may create
6453  // object w/o privileges
6454  SysCatalog::instance().createDBObject(
6455  session.get_currentUser(), view_name_, ViewDBObjectType, catalog);
6456 }
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: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:1944
const UserMetadata & get_currentUser() const
Definition: SessionInfo.h:88
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: