OmniSciDB  29e35f4d58
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::SessionInfogetSession () const
 
std::shared_ptr< Catalog_Namespace::CataloggetCatalog () const
 
std::shared_ptr< CalcitegetCalcite () const
 
bool gpusPresent () const
 
virtual void clearGpuMemory () const
 
virtual void clearCpuMemory () const
 
virtual void runDDLStatement (const std::string &)
 
virtual std::shared_ptr< ResultSetrunSQL (const std::string &query_str, const ExecutorDeviceType device_type, const bool hoist_literals=true, const bool allow_loop_joins=true)
 
virtual 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::vector< std::shared_ptr< ResultSet > > runMultipleStatements (const std::string &, const ExecutorDeviceType)
 
virtual void runImport (Parser::CopyTableStmt *import_stmt)
 
virtual std::unique_ptr< Importer_NS::LoadergetLoader (const TableDescriptor *td) const
 
virtual void setIRFilename (const std::string &filename)
 
virtual ~QueryRunner ()
 
 QueryRunner (std::unique_ptr< Catalog_Namespace::SessionInfo > session)
 

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::QueryStatecreate_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)
 
Planner::RootPlanparsePlanLegacy (const std::string &query_str)
 
Planner::RootPlanparsePlanCalcite (QueryStateProxy)
 
Planner::RootPlanparsePlan (QueryStateProxy)
 

Protected Attributes

std::shared_ptr< Catalog_Namespace::SessionInfosession_info_
 

Static Protected Attributes

static std::unique_ptr< QueryRunnerqr_instance_ = nullptr
 

Private Attributes

std::unique_ptr< IRFileWriterir_file_writer_
 

Detailed Description

Definition at line 70 of file QueryRunner.h.

Constructor & Destructor Documentation

◆ ~QueryRunner()

virtual QueryRunner::QueryRunner::~QueryRunner ( )
inlinevirtual

Definition at line 157 of file QueryRunner.h.

157 {}

◆ QueryRunner() [1/2]

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

◆ QueryRunner() [2/2]

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

References ExtensionFunctionsWhitelist::add(), ExtensionFunctionsWhitelist::addUdfs(), MapDParameters::aggregator, anonymous_namespace{QueryRunner.cpp}::calcite_shutdown_handler(), CALCITEPORT, CHECK, Catalog_Namespace::DBMetadata::dbOwner, anonymous_namespace{QueryRunner.cpp}::g_calcite, g_serialize_temp_tables, GPU, MapDParameters::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(), Catalog_Namespace::Catalog::set(), logger::set_once_fatal_func(), and Catalog_Namespace::UserMetadata::userId.

127  {
129 
130  boost::filesystem::path base_path{db_path};
131  CHECK(boost::filesystem::exists(base_path));
132  auto system_db_file = base_path / "mapd_catalogs" / OMNISCI_DEFAULT_DB;
133  CHECK(boost::filesystem::exists(system_db_file));
134  auto data_dir = base_path / "mapd_data";
137 
140  g_calcite = std::make_shared<Calcite>(-1, CALCITEPORT, db_path, 1024, udf_filename);
141  ExtensionFunctionsWhitelist::add(g_calcite->getExtensionFunctionWhitelist());
142  if (!udf_filename.empty()) {
143  ExtensionFunctionsWhitelist::addUdfs(g_calcite->getUserDefinedFunctionWhitelist());
144  }
145 
147 
148  if (std::is_same<CudaBuildSelector, PreprocessorFalse>::value) {
149  uses_gpus = false;
150  }
151  MapDParameters mapd_params;
152  mapd_params.gpu_buffer_mem_bytes = max_gpu_mem;
153  mapd_params.aggregator = !leaf_servers.empty();
154 
155  auto data_mgr = std::make_shared<Data_Namespace::DataMgr>(
156  data_dir.string(), mapd_params, uses_gpus, -1, 0, reserved_gpu_mem);
157 
158  auto& sys_cat = Catalog_Namespace::SysCatalog::instance();
159 
160  sys_cat.init(base_path.string(),
161  data_mgr,
162  {},
163  g_calcite,
164  false,
165  mapd_params.aggregator,
166  string_servers);
167 
168  if (create_user) {
169  if (!sys_cat.getMetadataForUser(user_name, user)) {
170  sys_cat.createUser(user_name, passwd, false, "", true);
171  }
172  }
173  CHECK(sys_cat.getMetadataForUser(user_name, user));
174  CHECK(bcrypt_checkpw(passwd.c_str(), user.passwd_hash.c_str()) == 0);
175 
176  if (create_db) {
177  if (!sys_cat.getMetadataForDB(db_name, db)) {
178  sys_cat.createDatabase(db_name, user.userId);
179  }
180  }
181  CHECK(sys_cat.getMetadataForDB(db_name, db));
182  CHECK(user.isSuper || (user.userId == db.dbOwner));
183  auto cat = std::make_shared<Catalog_Namespace::Catalog>(
184  base_path.string(), db, data_mgr, string_servers, g_calcite, create_db);
185  Catalog_Namespace::Catalog::set(cat->getCurrentDB().dbName, cat);
186  session_info_ = std::make_unique<Catalog_Namespace::SessionInfo>(
187  cat, user, ExecutorDeviceType::GPU, "");
188 }
static void addUdfs(const std::string &json_func_sigs)
#define CALCITEPORT
Definition: QueryRunner.cpp:39
bool g_serialize_temp_tables
Definition: Catalog.cpp:85
size_t gpu_buffer_mem_bytes
static void add(const std::string &json_func_sigs)
void set_once_fatal_func(FatalFunc fatal_func)
Definition: Logger.cpp:299
static SysCatalog & instance()
Definition: SysCatalog.h:257
const std::string OMNISCI_DEFAULT_DB
Definition: SysCatalog.h:59
static void set(const std::string &dbName, std::shared_ptr< Catalog > cat)
Definition: Catalog.cpp:3131
std::shared_ptr< Catalog_Namespace::SessionInfo > session_info_
Definition: QueryRunner.h:188
void register_signal_handler(int signum, void(*handler)(int))
Definition: MapDServer.cpp:116
std::shared_ptr< Calcite > g_calcite
Definition: QueryRunner.cpp:51
#define CHECK(condition)
Definition: Logger.h:193
std::atomic< bool > isSuper
Definition: SysCatalog.h:97
+ Here is the call graph for this function:

Member Function Documentation

◆ clearCpuMemory()

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

Definition at line 213 of file QueryRunner.cpp.

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

213  {
216 }
static void clearMemory(const Data_Namespace::MemoryLevel memory_level)
Definition: Execute.cpp:157
static SysCatalog & instance()
Definition: SysCatalog.h:257
#define CHECK(condition)
Definition: Logger.h:193
+ Here is the call graph for this function:

◆ clearGpuMemory()

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

Definition at line 208 of file QueryRunner.cpp.

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

208  {
211 }
static void clearMemory(const Data_Namespace::MemoryLevel memory_level)
Definition: Execute.cpp:157
static SysCatalog & instance()
Definition: SysCatalog.h:257
#define CHECK(condition)
Definition: Logger.h:193
+ Here is the call graph for this function:

◆ create_query_state()

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

Definition at line 164 of file QueryRunner.h.

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

164  {
165  return query_states_.create(std::forward<Ts>(args)...);
166  }
static query_state::QueryStates query_states_
Definition: QueryRunner.h:161
CircleBuffer::value_type create(ARGS &&... args)
Definition: QueryState.h:185
+ Here is the call graph for this function:

◆ get()

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

Definition at line 117 of file QueryRunner.h.

117  {
118  if (!qr_instance_) {
119  throw std::runtime_error("QueryRunner must be initialized before calling get().");
120  }
121  return qr_instance_.get();
122  }
static std::unique_ptr< QueryRunner > qr_instance_
Definition: QueryRunner.h:186

◆ getCalcite()

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

Definition at line 198 of file QueryRunner.cpp.

References anonymous_namespace{QueryRunner.cpp}::g_calcite.

198  {
199  // TODO: Embed Calcite shared_ptr ownership in QueryRunner
200  return g_calcite;
201 }
std::shared_ptr< Calcite > g_calcite
Definition: QueryRunner.cpp:51

◆ getCatalog()

std::shared_ptr< Catalog_Namespace::Catalog > QueryRunner::QueryRunner::getCatalog ( ) const

Definition at line 193 of file QueryRunner.cpp.

References CHECK.

193  {
195  return session_info_->get_catalog_ptr();
196 }
std::shared_ptr< Catalog_Namespace::SessionInfo > session_info_
Definition: QueryRunner.h:188
#define CHECK(condition)
Definition: Logger.h:193

◆ getLoader()

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

Definition at line 340 of file QueryRunner.cpp.

341  {
342  auto cat = getCatalog();
343  return std::make_unique<Importer_NS::Loader>(*cat, td);
344 }
std::shared_ptr< Catalog_Namespace::Catalog > getCatalog() const

◆ getSession()

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

Definition at line 126 of file QueryRunner.h.

126  {
127  return session_info_;
128  }
std::shared_ptr< Catalog_Namespace::SessionInfo > session_info_
Definition: QueryRunner.h:188

◆ gpusPresent()

bool QueryRunner::QueryRunner::gpusPresent ( ) const

Definition at line 203 of file QueryRunner.cpp.

References CHECK.

203  {
205  return session_info_->getCatalog().getDataMgr().gpusPresent();
206 }
std::shared_ptr< Catalog_Namespace::SessionInfo > session_info_
Definition: QueryRunner.h:188
#define CHECK(condition)
Definition: Logger.h:193

◆ init() [1/4]

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 72 of file QueryRunner.h.

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

75  {
76  return QueryRunner::init(db_path,
77  std::string{OMNISCI_ROOT_USER},
78  "HyperInteractive",
79  std::string{OMNISCI_DEFAULT_DB},
80  {},
81  {},
82  udf_filename,
83  true,
84  max_gpu_mem,
85  reserved_gpu_mem);
86  }
void init(LogOptions const &log_opts)
Definition: Logger.cpp:272
const std::string OMNISCI_DEFAULT_DB
Definition: SysCatalog.h:59
const std::string OMNISCI_ROOT_USER
Definition: SysCatalog.h:60
+ Here is the call graph for this function:

◆ init() [2/4]

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 88 of file QueryRunner.h.

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

90  {
91  return QueryRunner::init(db_path,
92  std::string{OMNISCI_ROOT_USER},
93  "HyperInteractive",
94  std::string{OMNISCI_DEFAULT_DB},
95  string_servers,
96  leaf_servers);
97  }
void init(LogOptions const &log_opts)
Definition: Logger.cpp:272
const std::string OMNISCI_DEFAULT_DB
Definition: SysCatalog.h:59
const std::string OMNISCI_ROOT_USER
Definition: SysCatalog.h:60
+ Here is the call graph for this function:

◆ init() [3/4]

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

References CHECK, logger::FATAL, and LOG_IF.

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

◆ init() [4/4]

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

Definition at line 112 of file QueryRunner.h.

References reset().

112  {
113  qr_instance_.reset(new QueryRunner(std::move(session)));
114  return qr_instance_.get();
115  }
QueryRunner(std::unique_ptr< Catalog_Namespace::SessionInfo > session)
static std::unique_ptr< QueryRunner > qr_instance_
Definition: QueryRunner.h:186
+ Here is the call graph for this function:

◆ parsePlan()

Planner::RootPlan * QueryRunner::QueryRunner::parsePlan ( QueryStateProxy  query_state_proxy)
protected

Definition at line 69 of file ParserUtils.cpp.

69  {
70  return parsePlanCalcite(query_state_proxy);
71 }
Planner::RootPlan * parsePlanCalcite(QueryStateProxy)
Definition: ParserUtils.cpp:48

◆ parsePlanCalcite()

Planner::RootPlan * QueryRunner::QueryRunner::parsePlanCalcite ( QueryStateProxy  query_state_proxy)
protected

Definition at line 48 of file ParserUtils.cpp.

References query_state::QueryStateProxy::getQueryState(), pg_shim(), and translate_query().

48  {
49  auto const& query_state = query_state_proxy.getQueryState();
50  ParserWrapper pw{query_state.getQueryStr()};
51  if (pw.isOtherExplain() || pw.is_ddl || pw.is_update_dml) {
52  return parsePlanLegacy(query_state.getQueryStr());
53  }
54 
55  const auto& cat = query_state.getConstSessionInfo()->getCatalog();
56  auto calcite_mgr = cat.getCalciteMgr();
57  const auto query_ra =
58  calcite_mgr
59  ->process(query_state_proxy,
60  pg_shim(query_state.getQueryStr()),
61  {},
62  true,
63  false,
64  false)
65  .plan_result; // if we want to be able to check plans we may want to calc this
66  return translate_query(query_ra, cat);
67 }
QueryState & getQueryState()
Definition: QueryState.h:172
Planner::RootPlan * parsePlanLegacy(const std::string &query_str)
Definition: ParserUtils.cpp:29
Planner::RootPlan * translate_query(const std::string &query, const Catalog_Namespace::Catalog &cat)
std::string pg_shim(const std::string &query)
+ Here is the call graph for this function:

◆ parsePlanLegacy()

Planner::RootPlan * QueryRunner::QueryRunner::parsePlanLegacy ( const std::string &  query_str)
protected

Definition at line 29 of file ParserUtils.cpp.

References Parser::DMLStmt::analyze(), CHECK, CHECK_EQ, Planner::RootPlan::getCatalog(), Planner::Optimizer::optimize(), and run_benchmark_import::parser.

29  {
30  const auto& cat = session_info_->getCatalog();
31  SQLParser parser;
32  std::list<std::unique_ptr<Parser::Stmt>> parse_trees;
33  std::string last_parsed;
34  if (parser.parse(query_str, parse_trees, last_parsed)) {
35  throw std::runtime_error("Failed to parse query: " + query_str);
36  }
37  CHECK_EQ(parse_trees.size(), size_t(1));
38  const auto& stmt = parse_trees.front();
39  Parser::DDLStmt* ddl = dynamic_cast<Parser::DDLStmt*>(stmt.get());
40  CHECK(!ddl);
41  Parser::DMLStmt* dml = dynamic_cast<Parser::DMLStmt*>(stmt.get());
42  Analyzer::Query query;
43  dml->analyze(cat, query);
44  Planner::Optimizer optimizer(query, cat);
45  return optimizer.optimize();
46 }
virtual void analyze(const Catalog_Namespace::Catalog &catalog, Analyzer::Query &query) const =0
#define CHECK_EQ(x, y)
Definition: Logger.h:201
std::shared_ptr< Catalog_Namespace::SessionInfo > session_info_
Definition: QueryRunner.h:188
#define CHECK(condition)
Definition: Logger.h:193
+ Here is the call graph for this function:

◆ reset()

void QueryRunner::QueryRunner::reset ( )
static

Definition at line 469 of file QueryRunner.cpp.

References anonymous_namespace{QueryRunner.cpp}::calcite_shutdown_handler().

Referenced by init().

469  {
470  qr_instance_.reset(nullptr);
472 }
static std::unique_ptr< QueryRunner > qr_instance_
Definition: QueryRunner.h:186
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ runDDLStatement()

void QueryRunner::QueryRunner::runDDLStatement ( const std::string &  stmt_str_in)
virtual

Definition at line 218 of file QueryRunner.cpp.

References CHECK, CHECK_EQ, Catalog_Namespace::SysCatalog::instance(), run_benchmark_import::parser, and STDLOG.

Referenced by Importer_NS::ImportDriver::importGeoTable().

218  {
221 
222  auto stmt_str = stmt_str_in;
223  // First remove special chars
224  boost::algorithm::trim_left_if(stmt_str, boost::algorithm::is_any_of("\n"));
225  // Then remove spaces
226  boost::algorithm::trim_left(stmt_str);
227 
228  auto query_state = create_query_state(session_info_, stmt_str);
229  auto stdlog = STDLOG(query_state);
230 
231  SQLParser parser;
232  std::list<std::unique_ptr<Parser::Stmt>> parse_trees;
233  std::string last_parsed;
234  CHECK_EQ(parser.parse(stmt_str, parse_trees, last_parsed), 0) << stmt_str_in;
235  CHECK_EQ(parse_trees.size(), size_t(1));
236  auto stmt = parse_trees.front().get();
237  auto ddl = dynamic_cast<Parser::DDLStmt*>(stmt);
238  CHECK(ddl);
239  ddl->execute(*session_info_);
240 }
#define CHECK_EQ(x, y)
Definition: Logger.h:201
static std::shared_ptr< query_state::QueryState > create_query_state(Ts &&... args)
Definition: QueryRunner.h:164
static SysCatalog & instance()
Definition: SysCatalog.h:257
std::shared_ptr< Catalog_Namespace::SessionInfo > session_info_
Definition: QueryRunner.h:188
#define CHECK(condition)
Definition: Logger.h:193
#define STDLOG(...)
Definition: QueryState.h:225
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ runImport()

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

Definition at line 335 of file QueryRunner.cpp.

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

335  {
336  CHECK(import_stmt);
337  import_stmt->execute(*session_info_);
338 }
void execute(const Catalog_Namespace::SessionInfo &session) override
std::shared_ptr< Catalog_Namespace::SessionInfo > session_info_
Definition: QueryRunner.h:188
#define CHECK(condition)
Definition: Logger.h:193
+ Here is the call graph for this function:

◆ runMultipleStatements()

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

Definition at line 303 of file QueryRunner.cpp.

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

305  {
306  std::vector<std::shared_ptr<ResultSet>> results;
307  // TODO: Need to properly handle escaped semicolons instead of doing a naive split().
308  auto fields = split(sql, ";");
309  for (const auto& field : fields) {
310  auto text = strip(field) + ";";
311  if (text == ";") {
312  continue;
313  }
314  // TODO: Maybe remove this redundant parsing after enhancing Parser::Stmt?
315  SQLParser parser;
316  std::list<std::unique_ptr<Parser::Stmt>> parse_trees;
317  std::string last_parsed;
318  CHECK_EQ(parser.parse(text, parse_trees, last_parsed), 0);
319  CHECK_EQ(parse_trees.size(), size_t(1));
320  auto stmt = parse_trees.front().get();
321  Parser::DDLStmt* ddl = dynamic_cast<Parser::DDLStmt*>(stmt);
322  Parser::DMLStmt* dml = dynamic_cast<Parser::DMLStmt*>(stmt);
323  if (ddl != nullptr && dml == nullptr) {
324  runDDLStatement(text);
325  results.push_back(nullptr);
326  } else if (ddl == nullptr && dml != nullptr) {
327  results.push_back(runSQL(text, dt, true, true));
328  } else {
329  throw std::runtime_error("Unexpected SQL statement type: " + text);
330  }
331  }
332  return results;
333 }
#define CHECK_EQ(x, y)
Definition: Logger.h:201
std::string strip(const std::string &str)
trim any whitespace from the left and right ends of a 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)
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:31
virtual void runDDLStatement(const std::string &)
std::vector< std::string > split(const std::string &str, const std::string &delim)
split apart a string into a vector of substrings
+ Here is the call graph for this function:

◆ runSelectQuery()

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

References CHECK, g_enable_columnar_output, g_enable_filter_push_down, g_gpu_mem_limit_percent, Executor::getExecutor(), Catalog_Namespace::SysCatalog::instance(), LoopStrengthReduction, pg_shim(), QueryRunner::anonymous_namespace{QueryRunner.cpp}::run_select_query_with_filter_push_down(), and STDLOG.

426  {
429  auto query_state = create_query_state(session_info_, query_str);
430  auto stdlog = STDLOG(query_state);
432  return run_select_query_with_filter_push_down(query_state->createQueryStateProxy(),
433  device_type,
434  hoist_literals,
435  allow_loop_joins,
436  just_explain,
438  }
439 
440  const auto& cat = session_info_->getCatalog();
441  auto executor = Executor::getExecutor(cat.getCurrentDB().dbId);
442  CompilationOptions co = {
443  device_type, true, ExecutorOptLevel::LoopStrengthReduction, false};
445  true,
446  just_explain,
447  allow_loop_joins,
448  false,
449  false,
450  false,
451  false,
452  10000,
453  false,
454  false,
456  auto calcite_mgr = cat.getCalciteMgr();
457  const auto query_ra = calcite_mgr
458  ->process(query_state->createQueryStateProxy(),
459  pg_shim(query_str),
460  {},
461  true,
462  false,
463  false)
464  .plan_result;
465  return RelAlgExecutor(executor.get(), cat, query_ra)
466  .executeRelAlgQuery(co, eo, nullptr);
467 }
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)
static std::shared_ptr< Executor > getExecutor(const int db_id, const std::string &debug_dir="", const std::string &debug_file="", const MapDParameters mapd_parameters=MapDParameters())
Definition: Execute.cpp:127
static std::shared_ptr< query_state::QueryState > create_query_state(Ts &&... args)
Definition: QueryRunner.h:164
bool g_enable_columnar_output
Definition: Execute.cpp:86
static SysCatalog & instance()
Definition: SysCatalog.h:257
bool g_enable_filter_push_down
Definition: Execute.cpp:82
double g_gpu_mem_limit_percent
Definition: QueryRunner.cpp:44
std::shared_ptr< Catalog_Namespace::SessionInfo > session_info_
Definition: QueryRunner.h:188
#define CHECK(condition)
Definition: Logger.h:193
std::string pg_shim(const std::string &query)
#define STDLOG(...)
Definition: QueryState.h:225
+ Here is the call graph for this function:

◆ runSQL()

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

References CHECK, CHECK_EQ, Executor::getExecutor(), Catalog_Namespace::SysCatalog::instance(), LOG, LoopStrengthReduction, ParserWrapper::NotDML, run_benchmark_import::result, STDLOG, and logger::WARNING.

245  {
248 
249  ParserWrapper pw{query_str};
250  if (pw.isCalcitePathPermissable()) {
251  if (ir_file_writer_ && (pw.getDMLType() == ParserWrapper::DMLType::NotDML)) {
252  try {
253  const auto result = runSelectQuery(
254  query_str, device_type, hoist_literals, allow_loop_joins, true);
255  const auto crt_row = result.getRows()->getNextRow(true, true);
256  CHECK_EQ(size_t(1), crt_row.size());
257  const auto scalar_ir = boost::get<ScalarTargetValue>(&crt_row[0]);
258  CHECK(scalar_ir);
259  const auto ir_ns = boost::get<NullableString>(scalar_ir);
260  CHECK(ir_ns);
261  const auto ir_str = boost::get<std::string>(ir_ns);
262  CHECK(ir_str);
263  (*ir_file_writer_)(query_str, *ir_str);
264  } catch (const std::exception& e) {
265  LOG(WARNING) << "Failed to run EXPLAIN on SELECT query: " << query_str << " ("
266  << e.what() << "). Proceeding with query execution.";
267  }
268  }
269  const auto execution_result =
270  runSelectQuery(query_str, device_type, hoist_literals, allow_loop_joins);
271 
272  return execution_result.getRows();
273  }
274 
275  auto query_state = create_query_state(session_info_, query_str);
276  auto stdlog = STDLOG(query_state);
277 
278  const auto& cat = session_info_->getCatalog();
279  auto executor = Executor::getExecutor(cat.getCurrentDB().dbId);
280 
281  auto plan =
282  std::unique_ptr<Planner::RootPlan>(parsePlan(query_state->createQueryStateProxy()));
283 
284 #ifdef HAVE_CUDA
285  return executor->execute(plan.get(),
286  *session_info_,
287  hoist_literals,
288  device_type,
290  true,
291  allow_loop_joins);
292 #else
293  return executor->execute(plan.get(),
294  *session_info_,
295  hoist_literals,
296  device_type,
298  false,
299  allow_loop_joins);
300 #endif
301 }
#define CHECK_EQ(x, y)
Definition: Logger.h:201
virtual 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)
static std::shared_ptr< Executor > getExecutor(const int db_id, const std::string &debug_dir="", const std::string &debug_file="", const MapDParameters mapd_parameters=MapDParameters())
Definition: Execute.cpp:127
#define LOG(tag)
Definition: Logger.h:188
std::unique_ptr< IRFileWriter > ir_file_writer_
Definition: QueryRunner.h:191
static std::shared_ptr< query_state::QueryState > create_query_state(Ts &&... args)
Definition: QueryRunner.h:164
Planner::RootPlan * parsePlan(QueryStateProxy)
Definition: ParserUtils.cpp:69
static SysCatalog & instance()
Definition: SysCatalog.h:257
std::shared_ptr< Catalog_Namespace::SessionInfo > session_info_
Definition: QueryRunner.h:188
#define CHECK(condition)
Definition: Logger.h:193
#define STDLOG(...)
Definition: QueryState.h:225
+ Here is the call graph for this function:

◆ setIRFilename()

virtual void QueryRunner::QueryRunner::setIRFilename ( const std::string &  filename)
inlinevirtual

Definition at line 153 of file QueryRunner.h.

References logger::filename().

153  {
154  ir_file_writer_ = std::make_unique<IRFileWriter>(filename);
155  }
std::string filename(char const *path)
Definition: Logger.cpp:58
std::unique_ptr< IRFileWriter > ir_file_writer_
Definition: QueryRunner.h:191
+ Here is the call graph for this function:

Member Data Documentation

◆ ir_file_writer_

std::unique_ptr<IRFileWriter> QueryRunner::QueryRunner::ir_file_writer_
private

Definition at line 191 of file QueryRunner.h.

◆ qr_instance_

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

Definition at line 186 of file QueryRunner.h.

◆ query_states_

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

Definition at line 161 of file QueryRunner.h.

◆ session_info_

std::shared_ptr<Catalog_Namespace::SessionInfo> QueryRunner::QueryRunner::session_info_
protected

Definition at line 188 of file QueryRunner.h.

Referenced by Importer_NS::ImportDriver::importGeoTable().


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