OmniSciDB  06b3bd477c
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
QueryRunner::QueryRunner Class Reference

#include <QueryRunner.h>

+ Inheritance diagram for QueryRunner::QueryRunner:
+ Collaboration diagram for QueryRunner::QueryRunner:

Public Member Functions

std::shared_ptr
< Catalog_Namespace::SessionInfo
getSession () const
 
std::shared_ptr
< Catalog_Namespace::Catalog
getCatalog () const
 
std::shared_ptr< CalcitegetCalcite () const
 
std::shared_ptr< ExecutorgetExecutor () const
 
bool gpusPresent () const
 
virtual void clearGpuMemory () const
 
virtual void clearCpuMemory () const
 
virtual void runDDLStatement (const std::string &)
 
virtual std::shared_ptr
< ResultSet
runSQL (const std::string &query_str, const ExecutorDeviceType device_type, const bool hoist_literals=true, const bool allow_loop_joins=true)
 
virtual std::shared_ptr
< ExecutionResult
runSelectQuery (const std::string &query_str, const ExecutorDeviceType device_type, const bool hoist_literals, const bool allow_loop_joins, const bool just_explain=false)
 
virtual std::shared_ptr
< ResultSet
runSQLWithAllowingInterrupt (const std::string &query_str, std::shared_ptr< Executor > executor, const std::string &session_id, const ExecutorDeviceType device_type, const unsigned interrupt_check_freq=1000)
 
virtual std::vector
< std::shared_ptr< ResultSet > > 
runMultipleStatements (const std::string &, const ExecutorDeviceType)
 
virtual QueryHint getParsedQueryHintofQuery (const std::string &)
 
virtual void runImport (Parser::CopyTableStmt *import_stmt)
 
virtual std::unique_ptr
< import_export::Loader
getLoader (const TableDescriptor *td) const
 
const std::shared_ptr
< std::vector< int32_t > > & 
getCachedJoinHashTable (size_t idx)
 
const std::shared_ptr
< std::vector< int8_t > > & 
getCachedBaselineHashTable (size_t idx)
 
size_t getEntryCntCachedBaselineHashTable (size_t idx)
 
uint64_t getNumberOfCachedJoinHashTables ()
 
uint64_t getNumberOfCachedBaselineJoinHashTables ()
 
void resizeDispatchQueue (const size_t num_executors)
 
 QueryRunner (std::unique_ptr< Catalog_Namespace::SessionInfo > session)
 
virtual ~QueryRunner ()=default
 

Static Public Member Functions

static QueryRunnerinit (const char *db_path, const std::string &udf_filename="", const size_t max_gpu_mem=0, const int reserved_gpu_mem=256<< 20)
 
static QueryRunnerinit (const char *db_path, const std::vector< LeafHostInfo > &string_servers, const std::vector< LeafHostInfo > &leaf_servers)
 
static QueryRunnerinit (const char *db_path, const std::string &user, const std::string &pass, const std::string &db_name, const std::vector< LeafHostInfo > &string_servers, const std::vector< LeafHostInfo > &leaf_servers, const std::string &udf_filename="", bool uses_gpus=true, const size_t max_gpu_mem=0, const int reserved_gpu_mem=256<< 20, const bool create_user=false, const bool create_db=false)
 
static QueryRunnerinit (std::unique_ptr< Catalog_Namespace::SessionInfo > &session)
 
static QueryRunnerget ()
 
static void reset ()
 
template<typename... Ts>
static std::shared_ptr
< query_state::QueryState
create_query_state (Ts &&...args)
 

Static Public Attributes

static query_state::QueryStates query_states_
 

Protected Member Functions

 QueryRunner (const char *db_path, const std::string &user, const std::string &pass, const std::string &db_name, const std::vector< LeafHostInfo > &string_servers, const std::vector< LeafHostInfo > &leaf_servers, const std::string &udf_filename, bool uses_gpus, const size_t max_gpu_mem, const int reserved_gpu_mem, const bool create_user, const bool create_db)
 

Protected Attributes

std::shared_ptr
< Catalog_Namespace::SessionInfo
session_info_
 
std::unique_ptr
< QueryDispatchQueue
dispatch_queue_
 

Static Protected Attributes

static std::unique_ptr
< QueryRunner
qr_instance_ = nullptr
 

Detailed Description

Definition at line 59 of file QueryRunner.h.

Constructor & Destructor Documentation

QueryRunner::QueryRunner::QueryRunner ( std::unique_ptr< Catalog_Namespace::SessionInfo session)

Referenced by init().

+ Here is the caller graph for this function:

virtual QueryRunner::QueryRunner::~QueryRunner ( )
virtualdefault
QueryRunner::QueryRunner::QueryRunner ( const char *  db_path,
const std::string &  user,
const std::string &  pass,
const std::string &  db_name,
const std::vector< LeafHostInfo > &  string_servers,
const std::vector< LeafHostInfo > &  leaf_servers,
const std::string &  udf_filename,
bool  uses_gpus,
const size_t  max_gpu_mem,
const int  reserved_gpu_mem,
const bool  create_user,
const bool  create_db 
)
protected

Definition at line 120 of file QueryRunner.cpp.

References ExtensionFunctionsWhitelist::add(), ExtensionFunctionsWhitelist::addUdfs(), SystemParameters::aggregator, anonymous_namespace{QueryRunner.cpp}::calcite_shutdown_handler(), CALCITEPORT, cat(), CHECK(), Catalog_Namespace::DBMetadata::dbOwner, anonymous_namespace{QueryRunner.cpp}::g_calcite, g_serialize_temp_tables, GPU, SystemParameters::gpu_buffer_mem_bytes, table_functions::TableFunctionsFactory::init(), Catalog_Namespace::SysCatalog::instance(), Catalog_Namespace::UserMetadata::isSuper, OMNISCI_DEFAULT_DB, Catalog_Namespace::UserMetadata::passwd_hash, register_signal_handler(), session_info_, Catalog_Namespace::Catalog::set(), logger::set_once_fatal_func(), and Catalog_Namespace::UserMetadata::userId.

132  : dispatch_queue_(std::make_unique<QueryDispatchQueue>(1)) {
134 
135  boost::filesystem::path base_path{db_path};
136  CHECK(boost::filesystem::exists(base_path));
137  auto system_db_file = base_path / "mapd_catalogs" / OMNISCI_DEFAULT_DB;
138  CHECK(boost::filesystem::exists(system_db_file));
139  auto data_dir = base_path / "mapd_data";
142 
145  g_calcite =
146  std::make_shared<Calcite>(-1, CALCITEPORT, db_path, 1024, 5000, true, udf_filename);
147  ExtensionFunctionsWhitelist::add(g_calcite->getExtensionFunctionWhitelist());
148  if (!udf_filename.empty()) {
149  ExtensionFunctionsWhitelist::addUdfs(g_calcite->getUserDefinedFunctionWhitelist());
150  }
151 
153 
154 #ifndef HAVE_CUDA
155  uses_gpus = false;
156 #endif
157  SystemParameters mapd_params;
158  mapd_params.gpu_buffer_mem_bytes = max_gpu_mem;
159  mapd_params.aggregator = !leaf_servers.empty();
160 
161  auto data_mgr = std::make_shared<Data_Namespace::DataMgr>(
162  data_dir.string(), mapd_params, uses_gpus, -1, 0, reserved_gpu_mem);
163 
164  auto& sys_cat = Catalog_Namespace::SysCatalog::instance();
165 
166  sys_cat.init(base_path.string(),
167  data_mgr,
168  {},
169  g_calcite,
170  false,
171  mapd_params.aggregator,
172  string_servers);
173 
174  if (create_user) {
175  if (!sys_cat.getMetadataForUser(user_name, user)) {
176  sys_cat.createUser(user_name, passwd, false, "", true);
177  }
178  }
179  CHECK(sys_cat.getMetadataForUser(user_name, user));
180  CHECK(bcrypt_checkpw(passwd.c_str(), user.passwd_hash.c_str()) == 0);
181 
182  if (create_db) {
183  if (!sys_cat.getMetadataForDB(db_name, db)) {
184  sys_cat.createDatabase(db_name, user.userId);
185  }
186  }
187  CHECK(sys_cat.getMetadataForDB(db_name, db));
188  CHECK(user.isSuper || (user.userId == db.dbOwner));
189  auto cat = std::make_shared<Catalog_Namespace::Catalog>(
190  base_path.string(), db, data_mgr, string_servers, g_calcite, create_db);
191  Catalog_Namespace::Catalog::set(cat->getCurrentDB().dbName, cat);
192  session_info_ = std::make_unique<Catalog_Namespace::SessionInfo>(
193  cat, user, ExecutorDeviceType::GPU, "");
194 }
static void addUdfs(const std::string &json_func_sigs)
#define CALCITEPORT
Definition: QueryRunner.cpp:42
std::string cat(Ts &&...args)
std::unique_ptr< QueryDispatchQueue > dispatch_queue_
Definition: QueryRunner.h:188
static void add(const std::string &json_func_sigs)
void set_once_fatal_func(FatalFunc fatal_func)
Definition: Logger.cpp:303
static SysCatalog & instance()
Definition: SysCatalog.h:288
CHECK(cgen_state)
const std::string OMNISCI_DEFAULT_DB
Definition: SysCatalog.h:58
bool g_serialize_temp_tables
Definition: Catalog.cpp:95
static void set(const std::string &dbName, std::shared_ptr< Catalog > cat)
Definition: Catalog.cpp:3654
std::shared_ptr< Catalog_Namespace::SessionInfo > session_info_
Definition: QueryRunner.h:187
void register_signal_handler(int signum, void(*handler)(int))
Definition: MapDServer.cpp:91
std::shared_ptr< Calcite > g_calcite
Definition: QueryRunner.cpp:55
std::atomic< bool > isSuper
Definition: SysCatalog.h:96

+ Here is the call graph for this function:

Member Function Documentation

void QueryRunner::QueryRunner::clearCpuMemory ( ) const
virtual

Definition at line 224 of file QueryRunner.cpp.

References CHECK(), Executor::clearMemory(), Data_Namespace::CPU_LEVEL, and Catalog_Namespace::SysCatalog::instance().

224  {
227 }
static void clearMemory(const Data_Namespace::MemoryLevel memory_level)
Definition: Execute.cpp:170
static SysCatalog & instance()
Definition: SysCatalog.h:288
CHECK(cgen_state)

+ Here is the call graph for this function:

void QueryRunner::QueryRunner::clearGpuMemory ( ) const
virtual

Definition at line 219 of file QueryRunner.cpp.

References CHECK(), Executor::clearMemory(), Data_Namespace::GPU_LEVEL, and Catalog_Namespace::SysCatalog::instance().

219  {
222 }
static void clearMemory(const Data_Namespace::MemoryLevel memory_level)
Definition: Execute.cpp:170
static SysCatalog & instance()
Definition: SysCatalog.h:288
CHECK(cgen_state)

+ Here is the call graph for this function:

template<typename... Ts>
static std::shared_ptr<query_state::QueryState> QueryRunner::QueryRunner::create_query_state ( Ts &&...  args)
inlinestatic

Definition at line 167 of file QueryRunner.h.

References run_benchmark_import::args, query_state::QueryStates::create(), and query_states_.

Referenced by getExecutor(), getParsedQueryHintofQuery(), runDDLStatement(), runSelectQuery(), runSQL(), and runSQLWithAllowingInterrupt().

167  {
168  return query_states_.create(std::forward<Ts>(args)...);
169  }
static query_state::QueryStates query_states_
Definition: QueryRunner.h:164
CircleBuffer::value_type create(ARGS &&...args)
Definition: QueryState.h:185

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static QueryRunner* QueryRunner::QueryRunner::get ( )
inlinestatic

Definition at line 106 of file QueryRunner.h.

References qr_instance_.

106  {
107  if (!qr_instance_) {
108  throw std::runtime_error("QueryRunner must be initialized before calling get().");
109  }
110  return qr_instance_.get();
111  }
static std::unique_ptr< QueryRunner > qr_instance_
Definition: QueryRunner.h:185
const std::shared_ptr< std::vector< int8_t > > & QueryRunner::QueryRunner::getCachedBaselineHashTable ( size_t  idx)

Definition at line 596 of file QueryRunner.cpp.

References BaselineJoinHashTable::getCachedHashTable().

597  {
599 };
static const std::shared_ptr< std::vector< int8_t > > & getCachedHashTable(size_t idx)

+ Here is the call graph for this function:

const std::shared_ptr< std::vector< int32_t > > & QueryRunner::QueryRunner::getCachedJoinHashTable ( size_t  idx)

Definition at line 591 of file QueryRunner.cpp.

References JoinHashTable::getCachedHashTable().

592  {
594 };
static const std::shared_ptr< std::vector< int32_t > > & getCachedHashTable(size_t idx)

+ Here is the call graph for this function:

std::shared_ptr< Calcite > QueryRunner::QueryRunner::getCalcite ( ) const

Definition at line 209 of file QueryRunner.cpp.

References anonymous_namespace{QueryRunner.cpp}::g_calcite.

209  {
210  // TODO: Embed Calcite shared_ptr ownership in QueryRunner
211  return g_calcite;
212 }
std::shared_ptr< Calcite > g_calcite
Definition: QueryRunner.cpp:55
std::shared_ptr< Catalog_Namespace::Catalog > QueryRunner::QueryRunner::getCatalog ( ) const

Definition at line 204 of file QueryRunner.cpp.

References CHECK(), and session_info_.

Referenced by getLoader().

204  {
206  return session_info_->get_catalog_ptr();
207 }
CHECK(cgen_state)
std::shared_ptr< Catalog_Namespace::SessionInfo > session_info_
Definition: QueryRunner.h:187

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

size_t QueryRunner::QueryRunner::getEntryCntCachedBaselineHashTable ( size_t  idx)

Definition at line 601 of file QueryRunner.cpp.

References BaselineJoinHashTable::getEntryCntCachedHashTable().

601  {
603 }
static size_t getEntryCntCachedHashTable(size_t idx)

+ Here is the call graph for this function:

std::shared_ptr< Executor > QueryRunner::QueryRunner::getExecutor ( ) const

Definition at line 322 of file QueryRunner.cpp.

References CHECK(), create_query_state(), Executor::getExecutor(), Catalog_Namespace::SysCatalog::instance(), session_info_, STDLOG, and Executor::UNITARY_EXECUTOR_ID.

322  {
325  auto query_state = create_query_state(session_info_, "");
326  auto stdlog = STDLOG(query_state);
328  return executor;
329 }
static std::shared_ptr< Executor > getExecutor(const ExecutorId id, const std::string &debug_dir="", const std::string &debug_file="", const SystemParameters system_parameters=SystemParameters())
Definition: Execute.cpp:148
static SysCatalog & instance()
Definition: SysCatalog.h:288
CHECK(cgen_state)
std::shared_ptr< Catalog_Namespace::SessionInfo > session_info_
Definition: QueryRunner.h:187
static std::shared_ptr< query_state::QueryState > create_query_state(Ts &&...args)
Definition: QueryRunner.h:167
#define STDLOG(...)
Definition: QueryState.h:225
static const ExecutorId UNITARY_EXECUTOR_ID
Definition: Execute.h:303

+ Here is the call graph for this function:

std::unique_ptr< import_export::Loader > QueryRunner::QueryRunner::getLoader ( const TableDescriptor td) const
virtual

Definition at line 423 of file QueryRunner.cpp.

References cat(), and getCatalog().

424  {
425  auto cat = getCatalog();
426  return std::make_unique<import_export::Loader>(*cat, td);
427 }
std::string cat(Ts &&...args)
std::shared_ptr< Catalog_Namespace::Catalog > getCatalog() const

+ Here is the call graph for this function:

uint64_t QueryRunner::QueryRunner::getNumberOfCachedBaselineJoinHashTables ( )

Definition at line 609 of file QueryRunner.cpp.

References BaselineJoinHashTable::getNumberOfCachedHashTables().

609  {
611 };
static uint64_t getNumberOfCachedHashTables()

+ Here is the call graph for this function:

uint64_t QueryRunner::QueryRunner::getNumberOfCachedJoinHashTables ( )

Definition at line 605 of file QueryRunner.cpp.

References JoinHashTable::getNumberOfCachedHashTables().

605  {
607 };
static uint64_t getNumberOfCachedHashTables()

+ Here is the call graph for this function:

QueryHint QueryRunner::QueryRunner::getParsedQueryHintofQuery ( const std::string &  query_str)
virtual

Definition at line 242 of file QueryRunner.cpp.

References cat(), CHECK(), create_query_state(), Executor::getExecutor(), RelAlgExecutor::getParsedQueryHints(), Catalog_Namespace::SysCatalog::instance(), pg_shim(), session_info_, and Executor::UNITARY_EXECUTOR_ID.

242  {
245  auto query_state = create_query_state(session_info_, query_str);
246  const auto& cat = session_info_->getCatalog();
248  auto calcite_mgr = cat.getCalciteMgr();
249  const auto query_ra = calcite_mgr
250  ->process(query_state->createQueryStateProxy(),
251  pg_shim(query_str),
252  {},
253  true,
254  false,
255  false,
256  true)
257  .plan_result;
258  auto ra_executor = RelAlgExecutor(executor.get(), cat, query_ra);
259  const auto& query_hints = ra_executor.getParsedQueryHints();
260  return query_hints;
261 }
std::string cat(Ts &&...args)
static std::shared_ptr< Executor > getExecutor(const ExecutorId id, const std::string &debug_dir="", const std::string &debug_file="", const SystemParameters system_parameters=SystemParameters())
Definition: Execute.cpp:148
const QueryHint getParsedQueryHints() const
static SysCatalog & instance()
Definition: SysCatalog.h:288
CHECK(cgen_state)
std::shared_ptr< Catalog_Namespace::SessionInfo > session_info_
Definition: QueryRunner.h:187
static std::shared_ptr< query_state::QueryState > create_query_state(Ts &&...args)
Definition: QueryRunner.h:167
std::string pg_shim(const std::string &query)
static const ExecutorId UNITARY_EXECUTOR_ID
Definition: Execute.h:303

+ Here is the call graph for this function:

std::shared_ptr<Catalog_Namespace::SessionInfo> QueryRunner::QueryRunner::getSession ( ) const
inline

Definition at line 115 of file QueryRunner.h.

References session_info_.

115  {
116  return session_info_;
117  }
std::shared_ptr< Catalog_Namespace::SessionInfo > session_info_
Definition: QueryRunner.h:187
bool QueryRunner::QueryRunner::gpusPresent ( ) const

Definition at line 214 of file QueryRunner.cpp.

References CHECK(), and session_info_.

214  {
216  return session_info_->getCatalog().getDataMgr().gpusPresent();
217 }
CHECK(cgen_state)
std::shared_ptr< Catalog_Namespace::SessionInfo > session_info_
Definition: QueryRunner.h:187

+ Here is the call graph for this function:

static QueryRunner* QueryRunner::QueryRunner::init ( const char *  db_path,
const std::string &  udf_filename = "",
const size_t  max_gpu_mem = 0,
const int  reserved_gpu_mem = 256 << 20 
)
inlinestatic

Definition at line 61 of file QueryRunner.h.

References logger::init(), OMNISCI_DEFAULT_DB, and OMNISCI_ROOT_USER.

Referenced by EmbeddedDatabase::DBEngineImpl::DBEngineImpl().

64  {
65  return QueryRunner::init(db_path,
66  std::string{OMNISCI_ROOT_USER},
67  "HyperInteractive",
68  std::string{OMNISCI_DEFAULT_DB},
69  {},
70  {},
71  udf_filename,
72  true,
73  max_gpu_mem,
74  reserved_gpu_mem);
75  }
void init(LogOptions const &log_opts)
Definition: Logger.cpp:276
const std::string OMNISCI_DEFAULT_DB
Definition: SysCatalog.h:58
const std::string OMNISCI_ROOT_USER
Definition: SysCatalog.h:59

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static QueryRunner* QueryRunner::QueryRunner::init ( const char *  db_path,
const std::vector< LeafHostInfo > &  string_servers,
const std::vector< LeafHostInfo > &  leaf_servers 
)
inlinestatic

Definition at line 77 of file QueryRunner.h.

References logger::init(), OMNISCI_DEFAULT_DB, and OMNISCI_ROOT_USER.

79  {
80  return QueryRunner::init(db_path,
81  std::string{OMNISCI_ROOT_USER},
82  "HyperInteractive",
83  std::string{OMNISCI_DEFAULT_DB},
84  string_servers,
85  leaf_servers);
86  }
void init(LogOptions const &log_opts)
Definition: Logger.cpp:276
const std::string OMNISCI_DEFAULT_DB
Definition: SysCatalog.h:58
const std::string OMNISCI_ROOT_USER
Definition: SysCatalog.h:59

+ Here is the call graph for this function:

QueryRunner * QueryRunner::QueryRunner::init ( const char *  db_path,
const std::string &  user,
const std::string &  pass,
const std::string &  db_name,
const std::vector< LeafHostInfo > &  string_servers,
const std::vector< LeafHostInfo > &  leaf_servers,
const std::string &  udf_filename = "",
bool  uses_gpus = true,
const size_t  max_gpu_mem = 0,
const int  reserved_gpu_mem = 256 << 20,
const bool  create_user = false,
const bool  create_db = false 
)
static

Definition at line 91 of file QueryRunner.cpp.

References CHECK(), logger::FATAL, and LOG_IF.

102  {
103  LOG_IF(FATAL, !leaf_servers.empty()) << "Distributed test runner not supported.";
104  CHECK(leaf_servers.empty());
105  qr_instance_.reset(new QueryRunner(db_path,
106  user,
107  pass,
108  db_name,
109  string_servers,
110  leaf_servers,
111  udf_filename,
112  uses_gpus,
113  max_gpu_mem,
114  reserved_gpu_mem,
115  create_user,
116  create_db));
117  return qr_instance_.get();
118 }
#define LOG_IF(severity, condition)
Definition: Logger.h:287
CHECK(cgen_state)
QueryRunner(std::unique_ptr< Catalog_Namespace::SessionInfo > session)
static std::unique_ptr< QueryRunner > qr_instance_
Definition: QueryRunner.h:185
static unsigned pass
Definition: testing.h:29

+ Here is the call graph for this function:

static QueryRunner* QueryRunner::QueryRunner::init ( std::unique_ptr< Catalog_Namespace::SessionInfo > &  session)
inlinestatic

Definition at line 101 of file QueryRunner.h.

References qr_instance_, and QueryRunner().

101  {
102  qr_instance_.reset(new QueryRunner(std::move(session)));
103  return qr_instance_.get();
104  }
QueryRunner(std::unique_ptr< Catalog_Namespace::SessionInfo > session)
static std::unique_ptr< QueryRunner > qr_instance_
Definition: QueryRunner.h:185

+ Here is the call graph for this function:

void QueryRunner::QueryRunner::reset ( )
static

Definition at line 613 of file QueryRunner.cpp.

References anonymous_namespace{QueryRunner.cpp}::calcite_shutdown_handler(), and qr_instance_.

Referenced by EmbeddedDatabase::DBEngineImpl::reset().

613  {
614  qr_instance_.reset(nullptr);
616 }
static std::unique_ptr< QueryRunner > qr_instance_
Definition: QueryRunner.h:185

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void QueryRunner::QueryRunner::resizeDispatchQueue ( const size_t  num_executors)

Definition at line 196 of file QueryRunner.cpp.

References dispatch_queue_.

196  {
197  dispatch_queue_ = std::make_unique<QueryDispatchQueue>(num_executors);
198 }
std::unique_ptr< QueryDispatchQueue > dispatch_queue_
Definition: QueryRunner.h:188
void QueryRunner::QueryRunner::runDDLStatement ( const std::string &  stmt_str_in)
virtual

Definition at line 263 of file QueryRunner.cpp.

References QueryRunner::apply_copy_to_shim(), CHECK(), CHECK_EQ, create_query_state(), Catalog_Namespace::SysCatalog::instance(), run_benchmark_import::parser, session_info_, and STDLOG.

Referenced by EmbeddedDatabase::DBEngineImpl::executeDDL(), QueryRunner::ImportDriver::importGeoTable(), and runMultipleStatements().

263  {
266 
267  std::string stmt_str = stmt_str_in;
268  // First remove special chars
269  boost::algorithm::trim_left_if(stmt_str, boost::algorithm::is_any_of("\n"));
270  // Then remove spaces
271  boost::algorithm::trim_left(stmt_str);
272 
273  ParserWrapper pw{stmt_str};
274  if (pw.is_copy_to) {
275  stmt_str = apply_copy_to_shim(stmt_str_in);
276  }
277 
278  auto query_state = create_query_state(session_info_, stmt_str);
279  auto stdlog = STDLOG(query_state);
280 
281  SQLParser parser;
282  std::list<std::unique_ptr<Parser::Stmt>> parse_trees;
283  std::string last_parsed;
284  CHECK_EQ(parser.parse(stmt_str, parse_trees, last_parsed), 0) << stmt_str_in;
285  CHECK_EQ(parse_trees.size(), size_t(1));
286  auto stmt = parse_trees.front().get();
287  auto ddl = dynamic_cast<Parser::DDLStmt*>(stmt);
288  CHECK(ddl);
289  ddl->execute(*session_info_);
290 }
#define CHECK_EQ(x, y)
Definition: Logger.h:205
static SysCatalog & instance()
Definition: SysCatalog.h:288
CHECK(cgen_state)
std::shared_ptr< Catalog_Namespace::SessionInfo > session_info_
Definition: QueryRunner.h:187
static std::shared_ptr< query_state::QueryState > create_query_state(Ts &&...args)
Definition: QueryRunner.h:167
#define STDLOG(...)
Definition: QueryState.h:225
std::string apply_copy_to_shim(const std::string &query_str)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void QueryRunner::QueryRunner::runImport ( Parser::CopyTableStmt import_stmt)
virtual

Definition at line 418 of file QueryRunner.cpp.

References CHECK(), Parser::CopyTableStmt::execute(), and session_info_.

418  {
419  CHECK(import_stmt);
420  import_stmt->execute(*session_info_);
421 }
void execute(const Catalog_Namespace::SessionInfo &session) override
CHECK(cgen_state)
std::shared_ptr< Catalog_Namespace::SessionInfo > session_info_
Definition: QueryRunner.h:187

+ Here is the call graph for this function:

std::vector< std::shared_ptr< ResultSet > > QueryRunner::QueryRunner::runMultipleStatements ( const std::string &  sql,
const ExecutorDeviceType  dt 
)
virtual

Definition at line 386 of file QueryRunner.cpp.

References CHECK_EQ, field(), run_benchmark_import::parser, runDDLStatement(), runSQL(), split(), and strip().

388  {
389  std::vector<std::shared_ptr<ResultSet>> results;
390  // TODO: Need to properly handle escaped semicolons instead of doing a naive split().
391  auto fields = split(sql, ";");
392  for (const auto& field : fields) {
393  auto text = strip(field) + ";";
394  if (text == ";") {
395  continue;
396  }
397  // TODO: Maybe remove this redundant parsing after enhancing Parser::Stmt?
398  SQLParser parser;
399  std::list<std::unique_ptr<Parser::Stmt>> parse_trees;
400  std::string last_parsed;
401  CHECK_EQ(parser.parse(text, parse_trees, last_parsed), 0);
402  CHECK_EQ(parse_trees.size(), size_t(1));
403  auto stmt = parse_trees.front().get();
404  Parser::DDLStmt* ddl = dynamic_cast<Parser::DDLStmt*>(stmt);
405  Parser::DMLStmt* dml = dynamic_cast<Parser::DMLStmt*>(stmt);
406  if (ddl != nullptr && dml == nullptr) {
407  runDDLStatement(text);
408  results.push_back(nullptr);
409  } else if (ddl == nullptr && dml != nullptr) {
410  results.push_back(runSQL(text, dt, true, true));
411  } else {
412  throw std::runtime_error("Unexpected SQL statement type: " + text);
413  }
414  }
415  return results;
416 }
#define CHECK_EQ(x, y)
Definition: Logger.h:205
std::string strip(std::string_view str)
trim any whitespace from the left and right ends of a string
std::vector< std::string > split(std::string_view str, std::string_view delim, std::optional< size_t > maxsplit)
split apart a string into a vector of substrings
virtual std::shared_ptr< ResultSet > runSQL(const std::string &query_str, const ExecutorDeviceType device_type, const bool hoist_literals=true, const bool allow_loop_joins=true)
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:31
virtual void runDDLStatement(const std::string &)

+ Here is the call graph for this function:

std::shared_ptr< ExecutionResult > QueryRunner::QueryRunner::runSelectQuery ( const std::string &  query_str,
const ExecutorDeviceType  device_type,
const bool  hoist_literals,
const bool  allow_loop_joins,
const bool  just_explain = false 
)
virtual

Definition at line 517 of file QueryRunner.cpp.

References cat(), CHECK(), CPU, create_query_state(), CompilationOptions::defaults(), CompilationOptions::device_type, dispatch_queue_, g_enable_columnar_output, g_enable_filter_push_down, g_gpu_mem_limit_percent, Executor::getExecutor(), RelAlgExecutor::getParsedQueryHints(), Catalog_Namespace::SysCatalog::instance(), LoopStrengthReduction, CompilationOptions::opt_level, pg_shim(), run_benchmark_import::result, QueryRunner::anonymous_namespace{QueryRunner.cpp}::run_select_query_with_filter_push_down(), session_info_, and STDLOG.

Referenced by runSQL().

522  {
525  auto query_state = create_query_state(session_info_, query_str);
526  auto stdlog = STDLOG(query_state);
528  return run_select_query_with_filter_push_down(query_state->createQueryStateProxy(),
529  device_type,
530  hoist_literals,
531  allow_loop_joins,
532  just_explain,
534  }
535 
536  const auto& cat = session_info_->getCatalog();
537 
538  std::shared_ptr<ExecutionResult> result;
539  auto query_launch_task =
540  std::make_shared<QueryDispatchQueue::Task>([&cat,
541  &query_str,
542  &device_type,
543  &allow_loop_joins,
544  &just_explain,
545  &query_state,
546  &result](const size_t worker_id) {
547  auto executor = Executor::getExecutor(worker_id);
550 
552  true,
553  just_explain,
554  allow_loop_joins,
555  false,
556  false,
557  false,
558  false,
559  10000,
560  false,
561  false,
563  false,
564  1000};
565  auto calcite_mgr = cat.getCalciteMgr();
566  const auto query_ra = calcite_mgr
567  ->process(query_state->createQueryStateProxy(),
568  pg_shim(query_str),
569  {},
570  true,
571  false,
572  false,
573  true)
574  .plan_result;
575  auto ra_executor = RelAlgExecutor(executor.get(), cat, query_ra);
576  const auto& query_hints = ra_executor.getParsedQueryHints();
577  if (query_hints.cpu_mode) {
579  }
580  result = std::make_shared<ExecutionResult>(
581  ra_executor.executeRelAlgQuery(co, eo, false, nullptr));
582  });
584  dispatch_queue_->submit(query_launch_task);
585  auto result_future = query_launch_task->get_future();
586  result_future.get();
587  CHECK(result);
588  return result;
589 }
std::string cat(Ts &&...args)
std::unique_ptr< QueryDispatchQueue > dispatch_queue_
Definition: QueryRunner.h:188
static std::shared_ptr< Executor > getExecutor(const ExecutorId id, const std::string &debug_dir="", const std::string &debug_file="", const SystemParameters system_parameters=SystemParameters())
Definition: Execute.cpp:148
ExecutorOptLevel opt_level
bool g_enable_columnar_output
Definition: Execute.cpp:90
const QueryHint getParsedQueryHints() const
static SysCatalog & instance()
Definition: SysCatalog.h:288
CHECK(cgen_state)
double g_gpu_mem_limit_percent
Definition: QueryRunner.cpp:47
ExecutorDeviceType device_type
std::shared_ptr< Catalog_Namespace::SessionInfo > session_info_
Definition: QueryRunner.h:187
static std::shared_ptr< query_state::QueryState > create_query_state(Ts &&...args)
Definition: QueryRunner.h:167
static CompilationOptions defaults(const ExecutorDeviceType device_type=ExecutorDeviceType::GPU)
bool g_enable_filter_push_down
Definition: Execute.cpp:86
std::shared_ptr< ExecutionResult > run_select_query_with_filter_push_down(QueryStateProxy query_state_proxy, const ExecutorDeviceType device_type, const bool hoist_literals, const bool allow_loop_joins, const bool just_explain, const bool with_filter_push_down)
std::string pg_shim(const std::string &query)
#define STDLOG(...)
Definition: QueryState.h:225

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::shared_ptr< ResultSet > QueryRunner::QueryRunner::runSQL ( const std::string &  query_str,
const ExecutorDeviceType  device_type,
const bool  hoist_literals = true,
const bool  allow_loop_joins = true 
)
virtual

Definition at line 292 of file QueryRunner.cpp.

References CHECK(), CHECK_EQ, create_query_state(), Catalog_Namespace::SysCatalog::instance(), run_benchmark_import::parser, runSelectQuery(), session_info_, STDLOG, and VLOG.

Referenced by EmbeddedDatabase::DBEngineImpl::executeDML(), and runMultipleStatements().

295  {
298 
299  ParserWrapper pw{query_str};
300  if (pw.isCalcitePathPermissable()) {
301  const auto execution_result =
302  runSelectQuery(query_str, device_type, hoist_literals, allow_loop_joins);
303  VLOG(1) << session_info_->getCatalog().getDataMgr().getSystemMemoryUsage();
304  return execution_result->getRows();
305  }
306 
307  auto query_state = create_query_state(session_info_, query_str);
308  auto stdlog = STDLOG(query_state);
309 
310  SQLParser parser;
311  std::list<std::unique_ptr<Parser::Stmt>> parse_trees;
312  std::string last_parsed;
313  CHECK_EQ(parser.parse(query_str, parse_trees, last_parsed), 0) << query_str;
314  CHECK_EQ(parse_trees.size(), size_t(1));
315  auto stmt = parse_trees.front().get();
316  auto insert_values_stmt = dynamic_cast<InsertValuesStmt*>(stmt);
317  CHECK(insert_values_stmt);
318  insert_values_stmt->execute(*session_info_);
319  return nullptr;
320 }
#define CHECK_EQ(x, y)
Definition: Logger.h:205
static SysCatalog & instance()
Definition: SysCatalog.h:288
CHECK(cgen_state)
virtual std::shared_ptr< ExecutionResult > runSelectQuery(const std::string &query_str, const ExecutorDeviceType device_type, const bool hoist_literals, const bool allow_loop_joins, const bool just_explain=false)
std::shared_ptr< Catalog_Namespace::SessionInfo > session_info_
Definition: QueryRunner.h:187
static std::shared_ptr< query_state::QueryState > create_query_state(Ts &&...args)
Definition: QueryRunner.h:167
#define STDLOG(...)
Definition: QueryState.h:225
#define VLOG(n)
Definition: Logger.h:291

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::shared_ptr< ResultSet > QueryRunner::QueryRunner::runSQLWithAllowingInterrupt ( const std::string &  query_str,
std::shared_ptr< Executor executor,
const std::string &  session_id,
const ExecutorDeviceType  device_type,
const unsigned  interrupt_check_freq = 1000 
)
virtual

Definition at line 331 of file QueryRunner.cpp.

References calcite_lock, cat(), CHECK(), create_query_state(), CompilationOptions::defaults(), g_enable_columnar_output, g_gpu_mem_limit_percent, GPU, Catalog_Namespace::SysCatalog::instance(), pg_shim(), run_benchmark_import::result, session_info_, and STDLOG.

336  {
339  auto session_info =
340  std::make_shared<Catalog_Namespace::SessionInfo>(session_info_->get_catalog_ptr(),
341  session_info_->get_currentUser(),
343  session_id);
344  auto query_state = create_query_state(session_info, query_str);
345  auto stdlog = STDLOG(query_state);
346  const auto& cat = query_state->getConstSessionInfo()->getCatalog();
348 
350  true,
351  false,
352  true,
353  false,
354  false,
355  false,
356  false,
357  10000,
358  false,
359  false,
361  true,
362  interrupt_check_freq};
363  std::string query_ra{""};
364  {
365  // async query initiation for interrupt test
366  // incurs data race warning in TSAN since
367  // calcite_mgr is shared across multiple query threads
368  // so here we lock the manager during query parsing
369  std::lock_guard<std::mutex> calcite_lock_guard(calcite_lock);
370  auto calcite_mgr = cat.getCalciteMgr();
371  query_ra = calcite_mgr
372  ->process(query_state->createQueryStateProxy(),
373  pg_shim(query_state->getQueryStr()),
374  {},
375  true,
376  false,
377  false,
378  true)
379  .plan_result;
380  }
381  auto result = RelAlgExecutor(executor.get(), cat, query_ra, query_state)
382  .executeRelAlgQuery(co, eo, false, nullptr);
383  return result.getRows();
384 }
std::string cat(Ts &&...args)
std::mutex calcite_lock
Definition: QueryRunner.cpp:50
bool g_enable_columnar_output
Definition: Execute.cpp:90
static SysCatalog & instance()
Definition: SysCatalog.h:288
CHECK(cgen_state)
double g_gpu_mem_limit_percent
Definition: QueryRunner.cpp:47
std::shared_ptr< Catalog_Namespace::SessionInfo > session_info_
Definition: QueryRunner.h:187
static std::shared_ptr< query_state::QueryState > create_query_state(Ts &&...args)
Definition: QueryRunner.h:167
static CompilationOptions defaults(const ExecutorDeviceType device_type=ExecutorDeviceType::GPU)
std::string pg_shim(const std::string &query)
#define STDLOG(...)
Definition: QueryState.h:225

+ Here is the call graph for this function:

Member Data Documentation

std::unique_ptr<QueryDispatchQueue> QueryRunner::QueryRunner::dispatch_queue_
protected

Definition at line 188 of file QueryRunner.h.

Referenced by resizeDispatchQueue(), and runSelectQuery().

std::unique_ptr< QueryRunner > QueryRunner::QueryRunner::qr_instance_ = nullptr
staticprotected

Definition at line 185 of file QueryRunner.h.

Referenced by get(), init(), and reset().

query_state::QueryStates QueryRunner::QueryRunner::query_states_
static

Definition at line 164 of file QueryRunner.h.

Referenced by create_query_state().


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