OmniSciDB  95562058bd
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
DdlCommandExecutor Class Reference

#include <DdlCommandExecutor.h>

Public Member Functions

 DdlCommandExecutor (const std::string &ddl_statement, std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)
 
void execute (TQueryResult &_return)
 
bool isShowUserSessions ()
 
bool isShowQueries ()
 
bool isKillQuery ()
 
const std::string getTargetQuerySessionToKill ()
 

Private Attributes

rapidjson::Document ddl_query_
 
std::shared_ptr
< Catalog_Namespace::SessionInfo
const > 
session_ptr_
 

Detailed Description

Definition at line 170 of file DdlCommandExecutor.h.

Constructor & Destructor Documentation

DdlCommandExecutor::DdlCommandExecutor ( const std::string &  ddl_statement,
std::shared_ptr< Catalog_Namespace::SessionInfo const >  session_ptr 
)

Definition at line 59 of file DdlCommandExecutor.cpp.

References CHECK, and ddl_query_.

62  : session_ptr_(session_ptr) {
63  CHECK(!ddl_statement.empty());
64  ddl_query_.Parse(ddl_statement);
65  CHECK(ddl_query_.IsObject());
66  CHECK(ddl_query_.HasMember("payload"));
67  CHECK(ddl_query_["payload"].IsObject());
68  const auto& payload = ddl_query_["payload"].GetObject();
69  CHECK(payload.HasMember("command"));
70  CHECK(payload["command"].IsString());
71 }
std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr_
rapidjson::Document ddl_query_
#define CHECK(condition)
Definition: Logger.h:197

Member Function Documentation

void DdlCommandExecutor::execute ( TQueryResult &  _return)

Parses given JSON string and routes resulting payload to appropriate DDL command class for execution.

Parameters
_returnresult of DDL command execution (if applicable)

Definition at line 73 of file DdlCommandExecutor.cpp.

References CHECK, CHECK_EQ, ddl_query_, and session_ptr_.

Referenced by DBHandler::executeDdl(), and omnisci.cursor.Cursor::executemany().

73  {
74  const auto& payload = ddl_query_["payload"].GetObject();
75  const auto& ddl_command = std::string_view(payload["command"].GetString());
76  if (ddl_command == "CREATE_SERVER") {
77  CreateForeignServerCommand{payload, session_ptr_}.execute(_return);
78  } else if (ddl_command == "DROP_SERVER") {
79  DropForeignServerCommand{payload, session_ptr_}.execute(_return);
80  } else if (ddl_command == "CREATE_FOREIGN_TABLE") {
81  CreateForeignTableCommand{payload, session_ptr_}.execute(_return);
82  } else if (ddl_command == "DROP_FOREIGN_TABLE") {
83  DropForeignTableCommand{payload, session_ptr_}.execute(_return);
84  } else if (ddl_command == "SHOW_TABLES") {
85  ShowTablesCommand{payload, session_ptr_}.execute(_return);
86  } else if (ddl_command == "SHOW_DATABASES") {
87  ShowDatabasesCommand{payload, session_ptr_}.execute(_return);
88  } else if (ddl_command == "SHOW_SERVERS") {
89  ShowForeignServersCommand{payload, session_ptr_}.execute(_return);
90  } else if (ddl_command == "ALTER_SERVER") {
91  AlterForeignServerCommand{payload, session_ptr_}.execute(_return);
92  } else if (ddl_command == "REFRESH_FOREIGN_TABLES") {
93  RefreshForeignTablesCommand{payload, session_ptr_}.execute(_return);
94  } else if (ddl_command == "SHOW_QUERIES") {
95  std::cout << "SHOW QUERIES DDL is not ready yet!\n";
96  } else if (ddl_command == "KILL_QUERY") {
97  CHECK(payload.HasMember("querySession"));
98  const std::string& querySessionPayload = payload["querySession"].GetString();
99  auto querySession = querySessionPayload.substr(1, 8);
100  CHECK_EQ(querySession.length(),
101  (unsigned long)8); // public_session_id's length + two quotes
102  std::cout << "TRY TO KILL QUERY " << querySession
103  << " BUT KILL QUERY DDL is not ready yet!\n";
104  } else {
105  throw std::runtime_error("Unsupported DDL command");
106  }
107 }
#define CHECK_EQ(x, y)
Definition: Logger.h:205
std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr_
rapidjson::Document ddl_query_
#define CHECK(condition)
Definition: Logger.h:197

+ Here is the caller graph for this function:

const std::string DdlCommandExecutor::getTargetQuerySessionToKill ( )

Returns target query session if this command is KILL QUERY

Definition at line 127 of file DdlCommandExecutor.cpp.

References CHECK, ddl_query_, and isKillQuery().

Referenced by DBHandler::executeDdl().

127  {
128  // caller should check whether DDL indicates KillQuery request
129  // i.e., use isKillQuery() before calling this function
130  const auto& payload = ddl_query_["payload"].GetObject();
131  CHECK(isKillQuery());
132  CHECK(payload.HasMember("querySession"));
133  const std::string& query_session = payload["querySession"].GetString();
134  // regex matcher for public_session: start_time{3}-session_id{4} (Example:819-4RDo)
135  boost::regex session_id_regex{R"([0-9]{3}-[a-zA-Z0-9]{4})",
136  boost::regex::extended | boost::regex::icase};
137  if (!boost::regex_match(query_session, session_id_regex)) {
138  throw std::runtime_error(
139  "Please provide the correct session ID of the query that you want to interrupt.");
140  }
141  return query_session;
142 }
rapidjson::Document ddl_query_
#define CHECK(condition)
Definition: Logger.h:197

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool DdlCommandExecutor::isKillQuery ( )

Returns true if this command is KILL QUERY

Definition at line 121 of file DdlCommandExecutor.cpp.

References ddl_query_.

Referenced by DBHandler::executeDdl(), and getTargetQuerySessionToKill().

121  {
122  const auto& payload = ddl_query_["payload"].GetObject();
123  const auto& ddl_command = std::string_view(payload["command"].GetString());
124  return (ddl_command == "KILL_QUERY");
125 }
rapidjson::Document ddl_query_

+ Here is the caller graph for this function:

bool DdlCommandExecutor::isShowQueries ( )

Returns true if this command is SHOW QUERIES

Definition at line 115 of file DdlCommandExecutor.cpp.

References ddl_query_.

Referenced by DBHandler::executeDdl().

115  {
116  const auto& payload = ddl_query_["payload"].GetObject();
117  const auto& ddl_command = std::string_view(payload["command"].GetString());
118  return (ddl_command == "SHOW_QUERIES");
119 }
rapidjson::Document ddl_query_

+ Here is the caller graph for this function:

bool DdlCommandExecutor::isShowUserSessions ( )

Returns true if this command is SHOW USER SESSIONS

Definition at line 109 of file DdlCommandExecutor.cpp.

References ddl_query_.

Referenced by DBHandler::executeDdl().

109  {
110  const auto& payload = ddl_query_["payload"].GetObject();
111  const auto& ddl_command = std::string_view(payload["command"].GetString());
112  return (ddl_command == "SHOW_USER_SESSIONS");
113 }
rapidjson::Document ddl_query_

+ Here is the caller graph for this function:

Member Data Documentation

rapidjson::Document DdlCommandExecutor::ddl_query_
private
std::shared_ptr<Catalog_Namespace::SessionInfo const> DdlCommandExecutor::session_ptr_
private

Definition at line 205 of file DdlCommandExecutor.h.

Referenced by execute().


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