OmniSciDB  72c90bc290
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
query_state::QueryState Class Reference

#include <QueryState.h>

+ Inheritance diagram for query_state::QueryState:
+ Collaboration diagram for query_state::QueryState:

Public Member Functions

QueryStateProxy createQueryStateProxy ()
 
QueryStateProxy createQueryStateProxy (Events::iterator parent)
 
Timer createTimer (char const *event_name, Events::iterator parent)
 
bool emptyLog () const
 
std::string const & getQueryStr () const
 
std::shared_ptr
< Catalog_Namespace::SessionInfo
const > 
getConstSessionInfo () const
 
boost::optional< SessionData >
const & 
getSessionData () const
 
bool isLogged () const
 
void logCallStack (std::stringstream &)
 
void setQuerySubmittedTime (const std::string &t)
 
const std::string getQuerySubmittedTime () const
 
void setLogged (bool logged)
 

Static Public Member Functions

template<typename... ARGS>
static std::shared_ptr
< QueryState
create (ARGS &&...args)
 

Private Member Functions

void logCallStack (std::stringstream &, unsigned const depth, Events::iterator parent)
 
 QueryState (std::shared_ptr< Catalog_Namespace::SessionInfo const > const &, std::string query_str)
 

Private Attributes

boost::optional< SessionDatasession_data_
 
std::string const query_str_
 
Events events_
 
std::mutex events_mutex_
 
std::atomic< bool > logged_
 
std::string submitted_
 

Friends

class QueryStates
 

Detailed Description

Definition at line 133 of file QueryState.h.

Constructor & Destructor Documentation

query_state::QueryState::QueryState ( std::shared_ptr< Catalog_Namespace::SessionInfo const > const &  session_info,
std::string  query_str 
)
private

Definition at line 62 of file QueryState.cpp.

Referenced by create().

65  : session_data_(session_info ? boost::make_optional<SessionData>(session_info)
66  : boost::none)
67  , query_str_(std::move(query_str))
68  , logged_(false)
69  , submitted_(::toString(std::chrono::system_clock::now())) {}
boost::optional< SessionData > session_data_
Definition: QueryState.h:134
std::string toString(const QueryDescriptionType &type)
Definition: Types.h:64
std::string submitted_
Definition: QueryState.h:139
std::string const query_str_
Definition: QueryState.h:135
std::atomic< bool > logged_
Definition: QueryState.h:138

+ Here is the caller graph for this function:

Member Function Documentation

template<typename... ARGS>
static std::shared_ptr<QueryState> query_state::QueryState::create ( ARGS &&...  args)
inlinestatic

Definition at line 148 of file QueryState.h.

References run_benchmark_import::args, and QueryState().

Referenced by Parser::CreateModelStmt::build_model_query(), query_state::QueryStates::create(), Parser::create_stmt_for_query(), ShowCreateTableCommand::execute(), EvaluateModelCommand::execute(), Parser::InsertIntoTableAsSelectStmt::execute(), Parser::CreateTableAsSelectStmt::execute(), Parser::ExportQueryStmt::execute(), Parser::CreateViewStmt::execute(), and Parser::CreateModelStmt::train_model().

148  {
149  // Trick to call std::make_shared with private constructors.
150  struct EnableMakeShared : public QueryState {
151  EnableMakeShared(ARGS&&... args) : QueryState(std::forward<ARGS>(args)...) {}
152  };
153  return std::make_shared<EnableMakeShared>(std::forward<ARGS>(args)...);
154  }
QueryState(std::shared_ptr< Catalog_Namespace::SessionInfo const > const &, std::string query_str)
Definition: QueryState.cpp:62

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

QueryStateProxy query_state::QueryState::createQueryStateProxy ( )

Definition at line 71 of file QueryState.cpp.

References events_.

Referenced by DBHandler::convertResultSet(), and Parser::ExportQueryStmt::execute().

71  {
72  return createQueryStateProxy(events_.end());
73 }
QueryStateProxy createQueryStateProxy()
Definition: QueryState.cpp:71

+ Here is the caller graph for this function:

QueryStateProxy query_state::QueryState::createQueryStateProxy ( Events::iterator  parent)

Definition at line 75 of file QueryState.cpp.

75  {
76  return QueryStateProxy(*this, parent);
77 }
Timer query_state::QueryState::createTimer ( char const *  event_name,
Events::iterator  parent 
)

Definition at line 79 of file QueryState.cpp.

References events_, and events_mutex_.

Referenced by query_state::QueryStateProxy::createTimer().

79  {
80  std::lock_guard<std::mutex> lock(events_mutex_);
81  return Timer(shared_from_this(), events_.emplace(events_.end(), event_name, parent));
82 }
std::mutex events_mutex_
Definition: QueryState.h:137

+ Here is the caller graph for this function:

bool query_state::QueryState::emptyLog ( ) const
inline

Definition at line 158 of file QueryState.h.

References events_, and query_str_.

158 { return events_.empty() && query_str_.empty(); }
std::string const query_str_
Definition: QueryState.h:135
std::shared_ptr< Catalog_Namespace::SessionInfo const > query_state::QueryState::getConstSessionInfo ( ) const

Definition at line 84 of file QueryState.cpp.

References session_data_.

Referenced by Calcite::checkAccessedObjectsPrivileges(), DBHandler::execute_rel_alg(), Parser::LocalQueryConnector::getOuterFragmentCount(), DBHandler::parse_to_ra(), Parser::InsertIntoTableAsSelectStmt::populateData(), Calcite::processImpl(), Parser::LocalQueryConnector::query(), QueryRunner::anonymous_namespace{QueryRunner.cpp}::run_select_query_with_filter_push_down(), and DBHandler::sql_execute_impl().

85  {
86  if (!session_data_) {
87  throw std::runtime_error("session_info_ was not set for this QueryState.");
88  }
89  if (auto retval = session_data_->session_info.lock()) {
90  return retval;
91  } else {
92  // This can happen for a query on a database that is simultaneously dropped.
93  throw std::runtime_error("session_info requested but has expired.");
94  }
95 }
boost::optional< SessionData > session_data_
Definition: QueryState.h:134

+ Here is the caller graph for this function:

std::string const& query_state::QueryState::getQueryStr ( ) const
inline

Definition at line 159 of file QueryState.h.

References query_str_.

Referenced by DBHandler::execute_rel_alg_with_filter_push_down(), QueryRunner::anonymous_namespace{QueryRunner.cpp}::run_select_query_with_filter_push_down(), and DBHandler::sql_execute_impl().

159 { return query_str_; }
std::string const query_str_
Definition: QueryState.h:135

+ Here is the caller graph for this function:

const std::string query_state::QueryState::getQuerySubmittedTime ( ) const

Definition at line 101 of file QueryState.cpp.

References events_mutex_, and submitted_.

Referenced by Parser::InsertIntoTableAsSelectStmt::populateData(), Parser::LocalQueryConnector::query(), and DBHandler::sql_execute_impl().

101  {
102  std::lock_guard<std::mutex> lock(events_mutex_);
103  return submitted_;
104 }
std::string submitted_
Definition: QueryState.h:139
std::mutex events_mutex_
Definition: QueryState.h:137

+ Here is the caller graph for this function:

boost::optional<SessionData> const& query_state::QueryState::getSessionData ( ) const
inline

Definition at line 162 of file QueryState.h.

References session_data_.

162 { return session_data_; }
boost::optional< SessionData > session_data_
Definition: QueryState.h:134
bool query_state::QueryState::isLogged ( ) const
inline

Definition at line 163 of file QueryState.h.

References logged_.

163 { return logged_.load(); }
std::atomic< bool > logged_
Definition: QueryState.h:138
void query_state::QueryState::logCallStack ( std::stringstream &  ss,
unsigned const  depth,
Events::iterator  parent 
)
private

Definition at line 107 of file QueryState.cpp.

References events_.

Referenced by logCallStack().

109  {
110  auto it = parent == events_.end() ? events_.begin() : std::next(parent);
111  for (; it != events_.end(); ++it) {
112  if (it->parent == parent) {
113  auto duration = it->duration(); // std::optional, true if event completed
114  ss << '\n'
115  << std::setw(depth << 1) << ' ' << it->name << ' ' << it->thread_id
116  << " - total time " << (duration ? *duration : -1) << " ms";
117  logCallStack(ss, depth + 1, it);
118  // If events_ is expendable, then this can be put here to speed-up large lists.
119  // it = events_.erase(it); } else { ++it; } (and remove above ++it.)
120  }
121  }
122 }
void logCallStack(std::stringstream &, unsigned const depth, Events::iterator parent)
Definition: QueryState.cpp:107

+ Here is the caller graph for this function:

void query_state::QueryState::logCallStack ( std::stringstream &  ss)

Definition at line 124 of file QueryState.cpp.

References events_, events_mutex_, and logCallStack().

124  {
125  std::lock_guard<std::mutex> lock(events_mutex_);
126  logCallStack(ss, 1, events_.end());
127 }
void logCallStack(std::stringstream &, unsigned const depth, Events::iterator parent)
Definition: QueryState.cpp:107
std::mutex events_mutex_
Definition: QueryState.h:137

+ Here is the call graph for this function:

void query_state::QueryState::setLogged ( bool  logged)
inline

Definition at line 167 of file QueryState.h.

References logged_.

167 { logged_.store(logged); }
std::atomic< bool > logged_
Definition: QueryState.h:138
void query_state::QueryState::setQuerySubmittedTime ( const std::string &  t)

Definition at line 97 of file QueryState.cpp.

References events_mutex_, and submitted_.

97  {
98  std::lock_guard<std::mutex> lock(events_mutex_);
99  submitted_ = t;
100 }
std::string submitted_
Definition: QueryState.h:139
std::mutex events_mutex_
Definition: QueryState.h:137

Friends And Related Function Documentation

friend class QueryStates
friend

Definition at line 168 of file QueryState.h.

Member Data Documentation

Events query_state::QueryState::events_
private

Definition at line 136 of file QueryState.h.

Referenced by createQueryStateProxy(), createTimer(), emptyLog(), and logCallStack().

std::mutex query_state::QueryState::events_mutex_
mutableprivate
std::atomic<bool> query_state::QueryState::logged_
private

Definition at line 138 of file QueryState.h.

Referenced by isLogged(), and setLogged().

std::string const query_state::QueryState::query_str_
private

Definition at line 135 of file QueryState.h.

Referenced by emptyLog(), and getQueryStr().

boost::optional<SessionData> query_state::QueryState::session_data_
private

Definition at line 134 of file QueryState.h.

Referenced by getConstSessionInfo(), and getSessionData().

std::string query_state::QueryState::submitted_
private

Definition at line 139 of file QueryState.h.

Referenced by getQuerySubmittedTime(), and setQuerySubmittedTime().


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