OmniSciDB  a5dc49c757
 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 6724 of file ParserNode.cpp.

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

6724  {
6725  CHECK(payload.HasMember("name"));
6726  view_name_ = json_str(payload["name"]);
6727 
6728  if_not_exists_ = false;
6729  if (payload.HasMember("ifNotExists")) {
6730  if_not_exists_ = json_bool(payload["ifNotExists"]);
6731  }
6732 
6733  CHECK(payload.HasMember("query"));
6734  select_query_ = json_str(payload["query"]);
6735  std::regex newline_re("\\n");
6736  select_query_ = std::regex_replace(select_query_, newline_re, " ");
6737  // ensure a trailing semicolon is present on the select query
6738  if (select_query_.back() != ';') {
6739  select_query_.push_back(';');
6740  }
6741 }
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 6743 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, lockmgr::instance(), 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().

6744  {
6745  if (read_only_mode) {
6746  throw std::runtime_error("CREATE VIEW invalid in read only mode.");
6747  }
6748  auto session_copy = session;
6749  auto session_ptr = std::shared_ptr<Catalog_Namespace::SessionInfo>(
6750  &session_copy, boost::null_deleter());
6751  auto query_state = query_state::QueryState::create(session_ptr, select_query_);
6752  auto stdlog = STDLOG(query_state);
6753  auto& catalog = session.getCatalog();
6754 
6755  if (!catalog.validateNonExistentTableOrView(view_name_, if_not_exists_)) {
6756  return;
6757  }
6760  throw std::runtime_error("View " + view_name_ +
6761  " will not be created. User has no create view privileges.");
6762  }
6763 
6764  const auto query_after_shim = pg_shim(select_query_);
6765  auto calcite_mgr = catalog.getCalciteMgr();
6766 
6767  // this now also ensures that access permissions are checked
6768  const auto calciteQueryParsingOption =
6769  calcite_mgr->getCalciteQueryParsingOption(true, false, true, false);
6770  const auto calciteOptimizationOption = calcite_mgr->getCalciteOptimizationOption(
6771  false, g_enable_watchdog, {}, SysCatalog::instance().isAggregator());
6772  calcite_mgr->process(query_state->createQueryStateProxy(),
6773  query_after_shim,
6774  calciteQueryParsingOption,
6775  calciteOptimizationOption);
6776 
6777  // Take write lock after the query is processed to ensure no deadlocks
6778  const auto execute_write_lock = legacylockmgr::getExecuteWriteLock();
6779 
6780  TableDescriptor td;
6781  td.tableName = view_name_;
6782  td.userId = session.get_currentUser().userId;
6783  td.nColumns = 0;
6784  td.isView = true;
6785  td.viewSQL = query_after_shim;
6786  td.fragmenter = nullptr;
6788  td.maxFragRows = DEFAULT_FRAGMENT_ROWS; // @todo this stuff should not be
6789  // InsertOrderFragmenter
6790  td.maxChunkSize = DEFAULT_MAX_CHUNK_SIZE; // @todo this stuff should not be
6791  // InsertOrderFragmenter
6794  catalog.createTable(td, {}, {}, true);
6795 
6796  // TODO (max): It's transactionally unsafe, should be fixed: we may create
6797  // object w/o privileges
6798  SysCatalog::instance().createDBObject(
6799  session.get_currentUser(), view_name_, ViewDBObjectType, catalog);
6800 }
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
T & instance()
Definition: LockMgr.cpp:101
Fragmenter_Namespace::FragmenterType fragType
std::string pg_shim(std::string const &query)
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
#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: