OmniSciDB  72c90bc290
 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 1870 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 1872 of file ParserNode.h.

1875  : view_name_(view_name)
1876  , select_query_(select_query)
1877  , if_not_exists_(if_not_exists) {}
std::string select_query_
Definition: ParserNode.h:1888
std::string view_name_
Definition: ParserNode.h:1887
Parser::CreateViewStmt::CreateViewStmt ( const rapidjson::Value &  payload)

Definition at line 6703 of file ParserNode.cpp.

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

6703  {
6704  CHECK(payload.HasMember("name"));
6705  view_name_ = json_str(payload["name"]);
6706 
6707  if_not_exists_ = false;
6708  if (payload.HasMember("ifNotExists")) {
6709  if_not_exists_ = json_bool(payload["ifNotExists"]);
6710  }
6711 
6712  CHECK(payload.HasMember("query"));
6713  select_query_ = json_str(payload["query"]);
6714  std::regex newline_re("\\n");
6715  select_query_ = std::regex_replace(select_query_, newline_re, " ");
6716  // ensure a trailing semicolon is present on the select query
6717  if (select_query_.back() != ';') {
6718  select_query_.push_back(';');
6719  }
6720 }
const bool json_bool(const rapidjson::Value &obj) noexcept
Definition: JsonAccessors.h:51
const std::string json_str(const rapidjson::Value &obj) noexcept
Definition: JsonAccessors.h:46
std::string select_query_
Definition: ParserNode.h:1888
#define CHECK(condition)
Definition: Logger.h:291
std::string view_name_
Definition: ParserNode.h:1887

+ 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 6722 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, TableDescriptor::fragmenter, TableDescriptor::fragPageSize, TableDescriptor::fragType, g_enable_watchdog, Catalog_Namespace::SessionInfo::get_currentUser(), Catalog_Namespace::SessionInfo::getCatalog(), legacylockmgr::getExecuteWriteLock(), if_not_exists_, Fragmenter_Namespace::INSERT_ORDER, TableDescriptor::isView, TableDescriptor::maxChunkSize, TableDescriptor::maxFragRows, TableDescriptor::maxRows, TableDescriptor::nColumns, pg_shim(), select_query_, STDLOG, TableDescriptor::tableName, TableDescriptor::userId, Catalog_Namespace::UserMetadata::userId, view_name_, ViewDBObjectType, and TableDescriptor::viewSQL.

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

6723  {
6724  if (read_only_mode) {
6725  throw std::runtime_error("CREATE VIEW invalid in read only mode.");
6726  }
6727  auto session_copy = session;
6728  auto session_ptr = std::shared_ptr<Catalog_Namespace::SessionInfo>(
6729  &session_copy, boost::null_deleter());
6730  auto query_state = query_state::QueryState::create(session_ptr, select_query_);
6731  auto stdlog = STDLOG(query_state);
6732  auto& catalog = session.getCatalog();
6733 
6734  if (!catalog.validateNonExistentTableOrView(view_name_, if_not_exists_)) {
6735  return;
6736  }
6739  throw std::runtime_error("View " + view_name_ +
6740  " will not be created. User has no create view privileges.");
6741  }
6742 
6743  const auto query_after_shim = pg_shim(select_query_);
6744  auto calcite_mgr = catalog.getCalciteMgr();
6745 
6746  // this now also ensures that access permissions are checked
6747  const auto calciteQueryParsingOption =
6748  calcite_mgr->getCalciteQueryParsingOption(true, false, true, false);
6749  const auto calciteOptimizationOption = calcite_mgr->getCalciteOptimizationOption(
6750  false, g_enable_watchdog, {}, SysCatalog::instance().isAggregator());
6751  calcite_mgr->process(query_state->createQueryStateProxy(),
6752  query_after_shim,
6753  calciteQueryParsingOption,
6754  calciteOptimizationOption);
6755 
6756  // Take write lock after the query is processed to ensure no deadlocks
6757  const auto execute_write_lock = legacylockmgr::getExecuteWriteLock();
6758 
6759  TableDescriptor td;
6760  td.tableName = view_name_;
6761  td.userId = session.get_currentUser().userId;
6762  td.nColumns = 0;
6763  td.isView = true;
6764  td.viewSQL = query_after_shim;
6765  td.fragmenter = nullptr;
6767  td.maxFragRows = DEFAULT_FRAGMENT_ROWS; // @todo this stuff should not be
6768  // InsertOrderFragmenter
6769  td.maxChunkSize = DEFAULT_MAX_CHUNK_SIZE; // @todo this stuff should not be
6770  // InsertOrderFragmenter
6773  catalog.createTable(td, {}, {}, true);
6774 
6775  // TODO (max): It's transactionally unsafe, should be fixed: we may create
6776  // object w/o privileges
6777  SysCatalog::instance().createDBObject(
6778  session.get_currentUser(), view_name_, ViewDBObjectType, catalog);
6779 }
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::string select_query_
Definition: ParserNode.h:1888
bool g_enable_watchdog
std::shared_ptr< Fragmenter_Namespace::AbstractFragmenter > fragmenter
#define DEFAULT_PAGE_SIZE
Catalog & getCatalog() const
Definition: SessionInfo.h:75
#define DEFAULT_FRAGMENT_ROWS
Fragmenter_Namespace::FragmenterType fragType
static const AccessPrivileges CREATE_VIEW
Definition: DBObject.h:178
auto getExecuteWriteLock()
std::string viewSQL
bool checkDBAccessPrivileges(const DBObjectType &permissionType, const AccessPrivileges &privs, const std::string &objectName="") const
Definition: SessionInfo.cpp:24
std::string view_name_
Definition: ParserNode.h:1887
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 1882 of file ParserNode.h.

References select_query_.

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

Definition at line 1881 of file ParserNode.h.

References view_name_.

1881 { return view_name_; }
std::string view_name_
Definition: ParserNode.h:1887

Member Data Documentation

bool Parser::CreateViewStmt::if_not_exists_
private

Definition at line 1889 of file ParserNode.h.

Referenced by CreateViewStmt(), and execute().

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

Definition at line 1888 of file ParserNode.h.

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

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

Definition at line 1887 of file ParserNode.h.

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


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