OmniSciDB  467d548b97
 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 108 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, fsi, 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, session_info_, Catalog_Namespace::Catalog::set(), logger::set_once_fatal_func(), anonymous_namespace{QueryRunner.cpp}::setup_signal_handler(), and Catalog_Namespace::UserMetadata::userId.

120  : dispatch_queue_(std::make_unique<QueryDispatchQueue>(1)) {
122 
123  boost::filesystem::path base_path{db_path};
124  CHECK(boost::filesystem::exists(base_path));
125  auto system_db_file = base_path / "mapd_catalogs" / OMNISCI_DEFAULT_DB;
126  CHECK(boost::filesystem::exists(system_db_file));
127  auto data_dir = base_path / "mapd_data";
128  DiskCacheConfig disk_cache_config{(base_path / "omnisci_disk_cache").string(),
132 
135  g_calcite =
136  std::make_shared<Calcite>(-1, CALCITEPORT, db_path, 1024, 5000, true, udf_filename);
137  ExtensionFunctionsWhitelist::add(g_calcite->getExtensionFunctionWhitelist());
138  if (!udf_filename.empty()) {
139  ExtensionFunctionsWhitelist::addUdfs(g_calcite->getUserDefinedFunctionWhitelist());
140  }
141 
143 
144 #ifndef HAVE_CUDA
145  uses_gpus = false;
146 #endif
147  SystemParameters mapd_params;
148  mapd_params.gpu_buffer_mem_bytes = max_gpu_mem;
149  mapd_params.aggregator = !leaf_servers.empty();
150 
151  auto data_mgr = std::make_shared<Data_Namespace::DataMgr>(data_dir.string(),
152  mapd_params,
153  uses_gpus,
154  -1,
155  0,
156  reserved_gpu_mem,
157  0,
158  disk_cache_config);
159 
160  auto& sys_cat = Catalog_Namespace::SysCatalog::instance();
161 
162  sys_cat.init(base_path.string(),
163  data_mgr,
164  {},
165  g_calcite,
166  false,
167  mapd_params.aggregator,
168  string_servers);
169 
170  if (create_user) {
171  if (!sys_cat.getMetadataForUser(user_name, user)) {
172  sys_cat.createUser(user_name, passwd, false, "", true);
173  }
174  }
175  CHECK(sys_cat.getMetadataForUser(user_name, user));
176  CHECK(bcrypt_checkpw(passwd.c_str(), user.passwd_hash.c_str()) == 0);
177 
178  if (create_db) {
179  if (!sys_cat.getMetadataForDB(db_name, db)) {
180  sys_cat.createDatabase(db_name, user.userId);
181  }
182  }
183  CHECK(sys_cat.getMetadataForDB(db_name, db));
184  CHECK(user.isSuper || (user.userId == db.dbOwner));
185  auto cat = std::make_shared<Catalog_Namespace::Catalog>(
186  base_path.string(), db, data_mgr, string_servers, g_calcite, create_db);
187  Catalog_Namespace::Catalog::set(cat->getCurrentDB().dbName, cat);
188  session_info_ = std::make_unique<Catalog_Namespace::SessionInfo>(
189  cat, user, ExecutorDeviceType::GPU, "");
190 }
static void addUdfs(const std::string &json_func_sigs)
#define CALCITEPORT
Definition: QueryRunner.cpp:43
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:307
static SysCatalog & instance()
Definition: SysCatalog.h:286
const std::string OMNISCI_DEFAULT_DB
Definition: SysCatalog.h:56
bool g_serialize_temp_tables
Definition: Catalog.cpp:96
static void set(const std::string &dbName, std::shared_ptr< Catalog > cat)
Definition: Catalog.cpp:3752
std::shared_ptr< Catalog_Namespace::SessionInfo > session_info_
Definition: QueryRunner.h:187
std::shared_ptr< Calcite > g_calcite
Definition: QueryRunner.cpp:57
#define CHECK(condition)
Definition: Logger.h:197
std::atomic< bool > isSuper
Definition: SysCatalog.h:94

+ Here is the call graph for this function:

Member Function Documentation

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

Definition at line 220 of file QueryRunner.cpp.

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

220  {
223 }
static void clearMemory(const Data_Namespace::MemoryLevel memory_level)
Definition: Execute.cpp:172
static SysCatalog & instance()
Definition: SysCatalog.h:286
#define CHECK(condition)
Definition: Logger.h:197

+ Here is the call graph for this function:

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

Definition at line 215 of file QueryRunner.cpp.

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

215  {
218 }
static void clearMemory(const Data_Namespace::MemoryLevel memory_level)
Definition: Execute.cpp:172
static SysCatalog & instance()
Definition: SysCatalog.h:286
#define CHECK(condition)
Definition: Logger.h:197

+ 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 592 of file QueryRunner.cpp.

References BaselineJoinHashTable::getCachedHashTable().

593  {
595 };
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 587 of file QueryRunner.cpp.

References JoinHashTable::getCachedHashTable().

588  {
590 };
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 205 of file QueryRunner.cpp.

References anonymous_namespace{QueryRunner.cpp}::g_calcite.

205  {
206  // TODO: Embed Calcite shared_ptr ownership in QueryRunner
207  return g_calcite;
208 }
std::shared_ptr< Calcite > g_calcite
Definition: QueryRunner.cpp:57
std::shared_ptr< Catalog_Namespace::Catalog > QueryRunner::QueryRunner::getCatalog ( ) const

Definition at line 200 of file QueryRunner.cpp.

References CHECK, and session_info_.

Referenced by getLoader().

200  {
202  return session_info_->get_catalog_ptr();
203 }
std::shared_ptr< Catalog_Namespace::SessionInfo > session_info_
Definition: QueryRunner.h:187
#define CHECK(condition)
Definition: Logger.h:197

+ Here is the caller graph for this function:

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

Definition at line 597 of file QueryRunner.cpp.

References BaselineJoinHashTable::getEntryCntCachedHashTable().

597  {
599 }
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 318 of file QueryRunner.cpp.

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

318  {
321  auto query_state = create_query_state(session_info_, "");
322  auto stdlog = STDLOG(query_state);
324  return executor;
325 }
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:150
static SysCatalog & instance()
Definition: SysCatalog.h:286
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 CHECK(condition)
Definition: Logger.h:197
#define STDLOG(...)
Definition: QueryState.h:225
static const ExecutorId UNITARY_EXECUTOR_ID
Definition: Execute.h:337

+ 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 419 of file QueryRunner.cpp.

References cat(), and getCatalog().

420  {
421  auto cat = getCatalog();
422  return std::make_unique<import_export::Loader>(*cat, td);
423 }
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 605 of file QueryRunner.cpp.

References BaselineJoinHashTable::getNumberOfCachedHashTables().

605  {
607 };
static uint64_t getNumberOfCachedHashTables()

+ Here is the call graph for this function:

uint64_t QueryRunner::QueryRunner::getNumberOfCachedJoinHashTables ( )

Definition at line 601 of file QueryRunner.cpp.

References JoinHashTable::getNumberOfCachedHashTables().

601  {
603 };
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 238 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.

238  {
241  auto query_state = create_query_state(session_info_, query_str);
242  const auto& cat = session_info_->getCatalog();
244  auto calcite_mgr = cat.getCalciteMgr();
245  const auto query_ra = calcite_mgr
246  ->process(query_state->createQueryStateProxy(),
247  pg_shim(query_str),
248  {},
249  true,
250  false,
251  false,
252  true)
253  .plan_result;
254  auto ra_executor = RelAlgExecutor(executor.get(), cat, query_ra);
255  const auto& query_hints = ra_executor.getParsedQueryHints();
256  return query_hints;
257 }
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:150
const QueryHint getParsedQueryHints() const
static SysCatalog & instance()
Definition: SysCatalog.h:286
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 CHECK(condition)
Definition: Logger.h:197
std::string pg_shim(const std::string &query)
static const ExecutorId UNITARY_EXECUTOR_ID
Definition: Execute.h:337

+ 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 210 of file QueryRunner.cpp.

References CHECK, and session_info_.

210  {
212  return session_info_->getCatalog().getDataMgr().gpusPresent();
213 }
std::shared_ptr< Catalog_Namespace::SessionInfo > session_info_
Definition: QueryRunner.h:187
#define CHECK(condition)
Definition: Logger.h:197
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:280
const std::string OMNISCI_DEFAULT_DB
Definition: SysCatalog.h:56
const std::string OMNISCI_ROOT_USER
Definition: SysCatalog.h:57

+ 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:280
const std::string OMNISCI_DEFAULT_DB
Definition: SysCatalog.h:56
const std::string OMNISCI_ROOT_USER
Definition: SysCatalog.h:57

+ 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 79 of file QueryRunner.cpp.

References CHECK, logger::FATAL, and LOG_IF.

90  {
91  LOG_IF(FATAL, !leaf_servers.empty()) << "Distributed test runner not supported.";
92  CHECK(leaf_servers.empty());
93  qr_instance_.reset(new QueryRunner(db_path,
94  user,
95  pass,
96  db_name,
97  string_servers,
98  leaf_servers,
99  udf_filename,
100  uses_gpus,
101  max_gpu_mem,
102  reserved_gpu_mem,
103  create_user,
104  create_db));
105  return qr_instance_.get();
106 }
#define LOG_IF(severity, condition)
Definition: Logger.h:287
QueryRunner(std::unique_ptr< Catalog_Namespace::SessionInfo > session)
static std::unique_ptr< QueryRunner > qr_instance_
Definition: QueryRunner.h:185
#define CHECK(condition)
Definition: Logger.h:197
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 609 of file QueryRunner.cpp.

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

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

609  {
610  qr_instance_.reset(nullptr);
612 }
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 192 of file QueryRunner.cpp.

References dispatch_queue_.

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

Definition at line 259 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().

259  {
262 
263  std::string stmt_str = stmt_str_in;
264  // First remove special chars
265  boost::algorithm::trim_left_if(stmt_str, boost::algorithm::is_any_of("\n"));
266  // Then remove spaces
267  boost::algorithm::trim_left(stmt_str);
268 
269  ParserWrapper pw{stmt_str};
270  if (pw.is_copy_to) {
271  stmt_str = apply_copy_to_shim(stmt_str_in);
272  }
273 
274  auto query_state = create_query_state(session_info_, stmt_str);
275  auto stdlog = STDLOG(query_state);
276 
277  SQLParser parser;
278  std::list<std::unique_ptr<Parser::Stmt>> parse_trees;
279  std::string last_parsed;
280  CHECK_EQ(parser.parse(stmt_str, parse_trees, last_parsed), 0) << stmt_str_in;
281  CHECK_EQ(parse_trees.size(), size_t(1));
282  auto stmt = parse_trees.front().get();
283  auto ddl = dynamic_cast<Parser::DDLStmt*>(stmt);
284  CHECK(ddl);
285  ddl->execute(*session_info_);
286 }
#define CHECK_EQ(x, y)
Definition: Logger.h:205
static SysCatalog & instance()
Definition: SysCatalog.h:286
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 CHECK(condition)
Definition: Logger.h:197
#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 414 of file QueryRunner.cpp.

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

414  {
415  CHECK(import_stmt);
416  import_stmt->execute(*session_info_);
417 }
void execute(const Catalog_Namespace::SessionInfo &session) override
std::shared_ptr< Catalog_Namespace::SessionInfo > session_info_
Definition: QueryRunner.h:187
#define CHECK(condition)
Definition: Logger.h:197

+ 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 382 of file QueryRunner.cpp.

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

384  {
385  std::vector<std::shared_ptr<ResultSet>> results;
386  // TODO: Need to properly handle escaped semicolons instead of doing a naive split().
387  auto fields = split(sql, ";");
388  for (const auto& field : fields) {
389  auto text = strip(field) + ";";
390  if (text == ";") {
391  continue;
392  }
393  // TODO: Maybe remove this redundant parsing after enhancing Parser::Stmt?
394  SQLParser parser;
395  std::list<std::unique_ptr<Parser::Stmt>> parse_trees;
396  std::string last_parsed;
397  CHECK_EQ(parser.parse(text, parse_trees, last_parsed), 0);
398  CHECK_EQ(parse_trees.size(), size_t(1));
399  auto stmt = parse_trees.front().get();
400  Parser::DDLStmt* ddl = dynamic_cast<Parser::DDLStmt*>(stmt);
401  Parser::DMLStmt* dml = dynamic_cast<Parser::DMLStmt*>(stmt);
402  if (ddl != nullptr && dml == nullptr) {
403  runDDLStatement(text);
404  results.push_back(nullptr);
405  } else if (ddl == nullptr && dml != nullptr) {
406  results.push_back(runSQL(text, dt, true, true));
407  } else {
408  throw std::runtime_error("Unexpected SQL statement type: " + text);
409  }
410  }
411  return results;
412 }
#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 513 of file QueryRunner.cpp.

References cat(), CHECK, CPU, create_query_state(), CompilationOptions::defaults(), CompilationOptions::device_type, dispatch_queue_, g_enable_calcite_view_optimize, 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().

518  {
521  auto query_state = create_query_state(session_info_, query_str);
522  auto stdlog = STDLOG(query_state);
524  return run_select_query_with_filter_push_down(query_state->createQueryStateProxy(),
525  device_type,
526  hoist_literals,
527  allow_loop_joins,
528  just_explain,
530  }
531 
532  const auto& cat = session_info_->getCatalog();
533 
534  std::shared_ptr<ExecutionResult> result;
535  auto query_launch_task =
536  std::make_shared<QueryDispatchQueue::Task>([&cat,
537  &query_str,
538  &device_type,
539  &allow_loop_joins,
540  &just_explain,
541  &query_state,
542  &result](const size_t worker_id) {
543  auto executor = Executor::getExecutor(worker_id);
546 
548  true,
549  just_explain,
550  allow_loop_joins,
551  false,
552  false,
553  false,
554  false,
555  10000,
556  false,
557  false,
559  false,
560  1000};
561  auto calcite_mgr = cat.getCalciteMgr();
562  const auto query_ra = calcite_mgr
563  ->process(query_state->createQueryStateProxy(),
564  pg_shim(query_str),
565  {},
566  true,
567  false,
569  true)
570  .plan_result;
571  auto ra_executor = RelAlgExecutor(executor.get(), cat, query_ra);
572  const auto& query_hints = ra_executor.getParsedQueryHints();
573  if (query_hints.cpu_mode) {
575  }
576  result = std::make_shared<ExecutionResult>(
577  ra_executor.executeRelAlgQuery(co, eo, false, nullptr));
578  });
580  dispatch_queue_->submit(query_launch_task, /*is_update_delete=*/false);
581  auto result_future = query_launch_task->get_future();
582  result_future.get();
583  CHECK(result);
584  return result;
585 }
bool g_enable_calcite_view_optimize
Definition: QueryRunner.cpp:51
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:150
ExecutorOptLevel opt_level
bool g_enable_columnar_output
Definition: Execute.cpp:91
const QueryHint getParsedQueryHints() const
static SysCatalog & instance()
Definition: SysCatalog.h:286
double g_gpu_mem_limit_percent
Definition: QueryRunner.cpp:48
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:87
#define CHECK(condition)
Definition: Logger.h:197
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 288 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().

291  {
294 
295  ParserWrapper pw{query_str};
296  if (pw.isCalcitePathPermissable()) {
297  const auto execution_result =
298  runSelectQuery(query_str, device_type, hoist_literals, allow_loop_joins);
299  VLOG(1) << session_info_->getCatalog().getDataMgr().getSystemMemoryUsage();
300  return execution_result->getRows();
301  }
302 
303  auto query_state = create_query_state(session_info_, query_str);
304  auto stdlog = STDLOG(query_state);
305 
306  SQLParser parser;
307  std::list<std::unique_ptr<Parser::Stmt>> parse_trees;
308  std::string last_parsed;
309  CHECK_EQ(parser.parse(query_str, parse_trees, last_parsed), 0) << query_str;
310  CHECK_EQ(parse_trees.size(), size_t(1));
311  auto stmt = parse_trees.front().get();
312  auto insert_values_stmt = dynamic_cast<InsertValuesStmt*>(stmt);
313  CHECK(insert_values_stmt);
314  insert_values_stmt->execute(*session_info_);
315  return nullptr;
316 }
#define CHECK_EQ(x, y)
Definition: Logger.h:205
static SysCatalog & instance()
Definition: SysCatalog.h:286
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 CHECK(condition)
Definition: Logger.h:197
#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 327 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.

332  {
335  auto session_info =
336  std::make_shared<Catalog_Namespace::SessionInfo>(session_info_->get_catalog_ptr(),
337  session_info_->get_currentUser(),
339  session_id);
340  auto query_state = create_query_state(session_info, query_str);
341  auto stdlog = STDLOG(query_state);
342  const auto& cat = query_state->getConstSessionInfo()->getCatalog();
344 
346  true,
347  false,
348  true,
349  false,
350  false,
351  false,
352  false,
353  10000,
354  false,
355  false,
357  true,
358  interrupt_check_freq};
359  std::string query_ra{""};
360  {
361  // async query initiation for interrupt test
362  // incurs data race warning in TSAN since
363  // calcite_mgr is shared across multiple query threads
364  // so here we lock the manager during query parsing
365  std::lock_guard<std::mutex> calcite_lock_guard(calcite_lock);
366  auto calcite_mgr = cat.getCalciteMgr();
367  query_ra = calcite_mgr
368  ->process(query_state->createQueryStateProxy(),
369  pg_shim(query_state->getQueryStr()),
370  {},
371  true,
372  false,
373  false,
374  true)
375  .plan_result;
376  }
377  auto result = RelAlgExecutor(executor.get(), cat, query_ra, query_state)
378  .executeRelAlgQuery(co, eo, false, nullptr);
379  return result.getRows();
380 }
std::string cat(Ts &&...args)
std::mutex calcite_lock
Definition: QueryRunner.cpp:52
bool g_enable_columnar_output
Definition: Execute.cpp:91
static SysCatalog & instance()
Definition: SysCatalog.h:286
double g_gpu_mem_limit_percent
Definition: QueryRunner.cpp:48
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)
#define CHECK(condition)
Definition: Logger.h:197
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: