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

#include <DdlCommandExecutor.h>

+ Collaboration diagram for DdlCommandExecutor:

Public Member Functions

 DdlCommandExecutor (const std::string &ddl_statement, std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)
 
ExecutionResult execute ()
 
bool isShowUserSessions ()
 
bool isShowQueries ()
 
bool isKillQuery ()
 
const std::string getTargetQuerySessionToKill ()
 
DistributedExecutionDetails getDistributedExecutionDetails ()
 
const std::string commandStr ()
 

Private Attributes

std::string ddl_statement_
 
std::string ddl_command_
 
std::unique_ptr< DdlCommandDataddl_data_
 
std::shared_ptr
< Catalog_Namespace::SessionInfo
const
session_ptr_
 

Detailed Description

Definition at line 193 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 312 of file DdlCommandExecutor.cpp.

References CHECK, ddl_command_, ddl_data_, ddl_statement_, and VLOG.

315  : session_ptr_(session_ptr) {
316  CHECK(!ddl_statement.empty());
317  ddl_statement_ = ddl_statement;
318 
319  // parse the incoming query,
320  // cache the parsed rapidjson object inside a DdlCommandDataImpl
321  // store the "abstract/base class" reference in ddl_data_
322  DdlCommandDataImpl* ddl_query_data = new DdlCommandDataImpl(ddl_statement);
323  ddl_data_ = std::unique_ptr<DdlCommandData>(ddl_query_data);
324 
325  VLOG(2) << "Parsing JSON DDL from Calcite: " << ddl_statement;
326  auto& ddl_query = ddl_query_data->query();
327  CHECK(ddl_query.IsObject()) << ddl_statement;
328  CHECK(ddl_query.HasMember("payload"));
329  CHECK(ddl_query["payload"].IsObject());
330  const auto& payload = ddl_query["payload"].GetObject();
331  CHECK(payload.HasMember("command"));
332  CHECK(payload["command"].IsString());
333  ddl_command_ = payload["command"].GetString();
334 }
std::unique_ptr< DdlCommandData > ddl_data_
std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr_
#define CHECK(condition)
Definition: Logger.h:206
#define VLOG(n)
Definition: Logger.h:300

Member Function Documentation

const std::string DdlCommandExecutor::commandStr ( )

Returns command string, can be useful for logging, conversion

Definition at line 460 of file DdlCommandExecutor.cpp.

References ddl_command_.

Referenced by DBHandler::executeDdl().

460  {
461  return ddl_command_;
462 }

+ Here is the caller graph for this function:

ExecutionResult DdlCommandExecutor::execute ( )

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

Parameters
returnExecutionResult of DDL command execution (if applicable)

Definition at line 336 of file DdlCommandExecutor.cpp.

References CHECK, CHECK_EQ, ddl_command_, ddl_data_, Parser::AlterTableStmt::delegateExecute(), logger::ERROR, legacylockmgr::ExecutorOuterLock, anonymous_namespace{DdlCommandExecutor.cpp}::extractPayload(), legacylockmgr::LockMgr< MutexType, KeyType >::getMutex(), LOG, run_benchmark_import::result, and session_ptr_.

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

336  {
338 
339  // the following commands use parser node locking to ensure safe concurrent access
340  if (ddl_command_ == "CREATE_TABLE") {
341  auto create_table_stmt = Parser::CreateTableStmt(extractPayload(*ddl_data_));
342  create_table_stmt.execute(*session_ptr_);
343  return result;
344  } else if (ddl_command_ == "CREATE_VIEW") {
345  auto create_view_stmt = Parser::CreateViewStmt(extractPayload(*ddl_data_));
346  create_view_stmt.execute(*session_ptr_);
347  return result;
348  } else if (ddl_command_ == "DROP_TABLE") {
349  auto drop_table_stmt = Parser::DropTableStmt(extractPayload(*ddl_data_));
350  drop_table_stmt.execute(*session_ptr_);
351  return result;
352  } else if (ddl_command_ == "DROP_VIEW") {
353  auto drop_view_stmt = Parser::DropViewStmt(extractPayload(*ddl_data_));
354  drop_view_stmt.execute(*session_ptr_);
355  return result;
356  } else if (ddl_command_ == "RENAME_TABLE") {
357  auto rename_table_stmt = Parser::RenameTableStmt(extractPayload(*ddl_data_));
358  rename_table_stmt.execute(*session_ptr_);
359  return result;
360  } else if (ddl_command_ == "ALTER_TABLE") {
362  return result;
363  }
364 
365  // the following commands require a global unique lock until proper table locking has
366  // been implemented and/or verified
367  auto execute_write_lock = mapd_unique_lock<mapd_shared_mutex>(
370  // TODO(vancouver): add appropriate table locking
371 
372  if (ddl_command_ == "CREATE_SERVER") {
373  result = CreateForeignServerCommand{*ddl_data_, session_ptr_}.execute();
374  } else if (ddl_command_ == "DROP_SERVER") {
375  result = DropForeignServerCommand{*ddl_data_, session_ptr_}.execute();
376  } else if (ddl_command_ == "CREATE_FOREIGN_TABLE") {
377  result = CreateForeignTableCommand{*ddl_data_, session_ptr_}.execute();
378  } else if (ddl_command_ == "DROP_FOREIGN_TABLE") {
379  result = DropForeignTableCommand{*ddl_data_, session_ptr_}.execute();
380  } else if (ddl_command_ == "SHOW_TABLES") {
381  result = ShowTablesCommand{*ddl_data_, session_ptr_}.execute();
382  } else if (ddl_command_ == "SHOW_TABLE_DETAILS") {
383  result = ShowTableDetailsCommand{*ddl_data_, session_ptr_}.execute();
384  } else if (ddl_command_ == "SHOW_DATABASES") {
385  result = ShowDatabasesCommand{*ddl_data_, session_ptr_}.execute();
386  } else if (ddl_command_ == "SHOW_SERVERS") {
387  result = ShowForeignServersCommand{*ddl_data_, session_ptr_}.execute();
388  } else if (ddl_command_ == "ALTER_SERVER") {
389  result = AlterForeignServerCommand{*ddl_data_, session_ptr_}.execute();
390  } else if (ddl_command_ == "ALTER_FOREIGN_TABLE") {
391  result = AlterForeignTableCommand{*ddl_data_, session_ptr_}.execute();
392  } else if (ddl_command_ == "REFRESH_FOREIGN_TABLES") {
393  result = RefreshForeignTablesCommand{*ddl_data_, session_ptr_}.execute();
394  } else if (ddl_command_ == "SHOW_QUERIES") {
395  LOG(ERROR) << "SHOW QUERIES DDL is not ready yet!\n";
396  } else if (ddl_command_ == "SHOW_DISK_CACHE_USAGE") {
397  result = ShowDiskCacheUsageCommand{*ddl_data_, session_ptr_}.execute();
398  } else if (ddl_command_ == "KILL_QUERY") {
399  auto& ddl_payload = extractPayload(*ddl_data_);
400  CHECK(ddl_payload.HasMember("querySession"));
401  const std::string& querySessionPayload = ddl_payload["querySession"].GetString();
402  auto querySession = querySessionPayload.substr(1, 8);
403  CHECK_EQ(querySession.length(),
404  (unsigned long)8); // public_session_id's length + two quotes
405  LOG(ERROR) << "TRY TO KILL QUERY " << querySession
406  << " BUT KILL QUERY DDL is not ready yet!\n";
407  } else {
408  throw std::runtime_error("Unsupported DDL command");
409  }
410 
411  return result;
412 }
#define CHECK_EQ(x, y)
Definition: Logger.h:214
static void delegateExecute(const rapidjson::Value &payload, const Catalog_Namespace::SessionInfo &session)
std::unique_ptr< DdlCommandData > ddl_data_
#define LOG(tag)
Definition: Logger.h:200
const rapidjson::Value & extractPayload(const DdlCommandData &ddl_data)
std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr_
static std::shared_ptr< MutexType > getMutex(const LockType lockType, const KeyType &key)
Definition: LegacyLockMgr.h:51
#define CHECK(condition)
Definition: Logger.h:206

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

DistributedExecutionDetails DdlCommandExecutor::getDistributedExecutionDetails ( )

Returns an object indicating where command execution should take place and how results should be aggregated for distributed setups.

Definition at line 426 of file DdlCommandExecutor.cpp.

References DistributedExecutionDetails::aggregation_type, AGGREGATOR_ONLY, ALL_NODES, ddl_command_, DistributedExecutionDetails::execution_location, LEAVES_ONLY, NONE, and UNION.

426  {
427  DistributedExecutionDetails execution_details;
428  if (ddl_command_ == "CREATE_TABLE" || ddl_command_ == "DROP_TABLE" ||
429  ddl_command_ == "CREATE_VIEW" || ddl_command_ == "DROP_VIEW" ||
430  ddl_command_ == "RENAME_TABLE" || ddl_command_ == "ALTER_TABLE") {
432  execution_details.aggregation_type = AggregationType::NONE;
433  } else if (ddl_command_ == "SHOW_TABLE_DETAILS") {
435  execution_details.aggregation_type = AggregationType::UNION;
436  } else {
438  execution_details.aggregation_type = AggregationType::NONE;
439  }
440  return execution_details;
441 }
ExecutionLocation execution_location
const std::string DdlCommandExecutor::getTargetQuerySessionToKill ( )

Returns target query session if this command is KILL QUERY

Definition at line 443 of file DdlCommandExecutor.cpp.

References CHECK, ddl_data_, anonymous_namespace{DdlCommandExecutor.cpp}::extractPayload(), and isKillQuery().

Referenced by DBHandler::executeDdl().

443  {
444  // caller should check whether DDL indicates KillQuery request
445  // i.e., use isKillQuery() before calling this function
446  auto& ddl_payload = extractPayload(*ddl_data_);
447  CHECK(isKillQuery());
448  CHECK(ddl_payload.HasMember("querySession"));
449  const std::string& query_session = ddl_payload["querySession"].GetString();
450  // regex matcher for public_session: start_time{3}-session_id{4} (Example:819-4RDo)
451  boost::regex session_id_regex{R"([0-9]{3}-[a-zA-Z0-9]{4})",
452  boost::regex::extended | boost::regex::icase};
453  if (!boost::regex_match(query_session, session_id_regex)) {
454  throw std::runtime_error(
455  "Please provide the correct session ID of the query that you want to interrupt.");
456  }
457  return query_session;
458 }
std::unique_ptr< DdlCommandData > ddl_data_
const rapidjson::Value & extractPayload(const DdlCommandData &ddl_data)
#define CHECK(condition)
Definition: Logger.h:206

+ 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 422 of file DdlCommandExecutor.cpp.

References ddl_command_.

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

422  {
423  return (ddl_command_ == "KILL_QUERY");
424 }

+ Here is the caller graph for this function:

bool DdlCommandExecutor::isShowQueries ( )

Returns true if this command is SHOW QUERIES

Definition at line 418 of file DdlCommandExecutor.cpp.

References ddl_command_.

Referenced by DBHandler::executeDdl().

418  {
419  return (ddl_command_ == "SHOW_QUERIES");
420 }

+ Here is the caller graph for this function:

bool DdlCommandExecutor::isShowUserSessions ( )

Returns true if this command is SHOW USER SESSIONS

Definition at line 414 of file DdlCommandExecutor.cpp.

References ddl_command_.

Referenced by DBHandler::executeDdl().

414  {
415  return (ddl_command_ == "SHOW_USER_SESSIONS");
416 }

+ Here is the caller graph for this function:

Member Data Documentation

std::string DdlCommandExecutor::ddl_command_
private
std::unique_ptr<DdlCommandData> DdlCommandExecutor::ddl_data_
private

Definition at line 241 of file DdlCommandExecutor.h.

Referenced by DdlCommandExecutor(), execute(), and getTargetQuerySessionToKill().

std::string DdlCommandExecutor::ddl_statement_
private

Definition at line 239 of file DdlCommandExecutor.h.

Referenced by DdlCommandExecutor().

std::shared_ptr<Catalog_Namespace::SessionInfo const> DdlCommandExecutor::session_ptr_
private

Definition at line 242 of file DdlCommandExecutor.h.

Referenced by execute().


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