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

Protected Attributes

std::shared_ptr
< Catalog_Namespace::SessionInfo
session_info_
 

Static Protected Attributes

static std::unique_ptr
< QueryRunner
qr_instance_ = nullptr
 

Private Attributes

std::unique_ptr< IRFileWriterir_file_writer_
 

Detailed Description

Definition at line 70 of file QueryRunner.h.

Constructor & Destructor Documentation

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

Definition at line 157 of file QueryRunner.h.

157 {}
QueryRunner::QueryRunner::QueryRunner ( std::unique_ptr< Catalog_Namespace::SessionInfo session)

Referenced by init().

+ Here is the caller graph for this function:

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 114 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, 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.

125  {
126  boost::filesystem::path base_path{db_path};
127  CHECK(boost::filesystem::exists(base_path));
128  auto system_db_file = base_path / "mapd_catalogs" / OMNISCI_DEFAULT_DB;
129  CHECK(boost::filesystem::exists(system_db_file));
130  auto data_dir = base_path / "mapd_data";
133 
136  g_calcite = std::make_shared<Calcite>(-1, CALCITEPORT, db_path, 1024, udf_filename);
137  ExtensionFunctionsWhitelist::add(g_calcite->getExtensionFunctionWhitelist());
138  if (!udf_filename.empty()) {
139  ExtensionFunctionsWhitelist::addUdfs(g_calcite->getUserDefinedFunctionWhitelist());
140  }
141 
143 
144  if (std::is_same<CudaBuildSelector, PreprocessorFalse>::value) {
145  uses_gpus = false;
146  }
147  MapDParameters 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>(
152  data_dir.string(), mapd_params, uses_gpus, -1, 0, reserved_gpu_mem);
153 
154  auto& sys_cat = Catalog_Namespace::SysCatalog::instance();
155 
156  sys_cat.init(base_path.string(),
157  data_mgr,
158  {},
159  g_calcite,
160  false,
161  mapd_params.aggregator,
162  string_servers);
163 
164  if (create_user) {
165  if (!sys_cat.getMetadataForUser(user_name, user)) {
166  sys_cat.createUser(user_name, passwd, false, "", true);
167  }
168  }
169  CHECK(sys_cat.getMetadataForUser(user_name, user));
170  CHECK(bcrypt_checkpw(passwd.c_str(), user.passwd_hash.c_str()) == 0);
171 
172  if (create_db) {
173  if (!sys_cat.getMetadataForDB(db_name, db)) {
174  sys_cat.createDatabase(db_name, user.userId);
175  }
176  }
177  CHECK(sys_cat.getMetadataForDB(db_name, db));
178  CHECK(user.isSuper || (user.userId == db.dbOwner));
179  auto cat = std::make_shared<Catalog_Namespace::Catalog>(
180  base_path.string(), db, data_mgr, string_servers, g_calcite, create_db);
181  Catalog_Namespace::Catalog::set(cat->getCurrentDB().dbName, cat);
182  session_info_ = std::make_unique<Catalog_Namespace::SessionInfo>(
183  cat, user, ExecutorDeviceType::GPU, "");
184 }
static void addUdfs(const std::string &json_func_sigs)
#define CALCITEPORT
Definition: QueryRunner.cpp:39
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:292
static SysCatalog & instance()
Definition: SysCatalog.h:257
CHECK(cgen_state)
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:2986
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:49
std::atomic< bool > isSuper
Definition: SysCatalog.h:97

+ Here is the call graph for this function:

Member Function Documentation

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

Definition at line 209 of file QueryRunner.cpp.

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

209  {
212 }
static void clearMemory(const Data_Namespace::MemoryLevel memory_level)
Definition: Execute.cpp:160
static SysCatalog & instance()
Definition: SysCatalog.h:257
CHECK(cgen_state)

+ Here is the call graph for this function:

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

Definition at line 204 of file QueryRunner.cpp.

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

204  {
207 }
static void clearMemory(const Data_Namespace::MemoryLevel memory_level)
Definition: Execute.cpp:160
static SysCatalog & instance()
Definition: SysCatalog.h:257
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 164 of file QueryRunner.h.

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

Referenced by runDDLStatement(), runSelectQuery(), and runSQL().

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:

+ Here is the caller graph for this function:

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

Definition at line 117 of file QueryRunner.h.

References qr_instance_.

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
std::shared_ptr< Calcite > QueryRunner::QueryRunner::getCalcite ( ) const

Definition at line 194 of file QueryRunner.cpp.

References anonymous_namespace{QueryRunner.cpp}::g_calcite.

194  {
195  // TODO: Embed Calcite shared_ptr ownership in QueryRunner
196  return g_calcite;
197 }
std::shared_ptr< Calcite > g_calcite
Definition: QueryRunner.cpp:49
std::shared_ptr< Catalog_Namespace::Catalog > QueryRunner::QueryRunner::getCatalog ( ) const

Definition at line 189 of file QueryRunner.cpp.

References CHECK(), and session_info_.

Referenced by getLoader().

189  {
191  return session_info_->get_catalog_ptr();
192 }
CHECK(cgen_state)
std::shared_ptr< Catalog_Namespace::SessionInfo > session_info_
Definition: QueryRunner.h:188

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 336 of file QueryRunner.cpp.

References getCatalog().

337  {
338  auto cat = getCatalog();
339  return std::make_unique<Importer_NS::Loader>(*cat, td);
340 }
std::shared_ptr< Catalog_Namespace::Catalog > getCatalog() const

+ Here is the call graph for this function:

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

Definition at line 126 of file QueryRunner.h.

References session_info_.

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

Definition at line 199 of file QueryRunner.cpp.

References CHECK(), and session_info_.

199  {
201  return session_info_->getCatalog().getDataMgr().gpusPresent();
202 }
CHECK(cgen_state)
std::shared_ptr< Catalog_Namespace::SessionInfo > session_info_
Definition: QueryRunner.h:188

+ 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 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:265
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:

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, and OMNISCI_ROOT_USER.

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:265
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:

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

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

96  {
97  LOG_IF(FATAL, !leaf_servers.empty()) << "Distributed test runner not supported.";
98  CHECK(leaf_servers.empty());
99  qr_instance_.reset(new QueryRunner(db_path,
100  user,
101  pass,
102  db_name,
103  string_servers,
104  leaf_servers,
105  udf_filename,
106  uses_gpus,
107  max_gpu_mem,
108  reserved_gpu_mem,
109  create_user,
110  create_db));
111  return qr_instance_.get();
112 }
#define LOG_IF(severity, condition)
Definition: Logger.h:276
CHECK(cgen_state)
QueryRunner(std::unique_ptr< Catalog_Namespace::SessionInfo > session)
static std::unique_ptr< QueryRunner > qr_instance_
Definition: QueryRunner.h:186
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 112 of file QueryRunner.h.

References qr_instance_, and QueryRunner().

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:

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

Definition at line 69 of file ParserUtils.cpp.

References parsePlanCalcite().

Referenced by runSQL().

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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 48 of file ParserUtils.cpp.

References Catalog_Namespace::Catalog::getCalciteMgr(), Planner::RootPlan::getCatalog(), query_state::QueryStateProxy::getQueryState(), parsePlanLegacy(), pg_shim(), and translate_query().

Referenced by parsePlan().

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 }
const Catalog_Namespace::Catalog & getCatalog() const
Definition: Planner.h:293
std::shared_ptr< Calcite > getCalciteMgr() const
Definition: Catalog.h:178
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:

+ Here is the caller graph for this function:

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::Optimizer::optimize(), run_benchmark_import::parser, and session_info_.

Referenced by parsePlanCalcite().

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:198
CHECK(cgen_state)
std::shared_ptr< Catalog_Namespace::SessionInfo > session_info_
Definition: QueryRunner.h:188

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void QueryRunner::QueryRunner::reset ( )
static

Definition at line 465 of file QueryRunner.cpp.

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

465  {
466  qr_instance_.reset(nullptr);
468 }
static std::unique_ptr< QueryRunner > qr_instance_
Definition: QueryRunner.h:186

+ Here is the call graph for this function:

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

Definition at line 214 of file QueryRunner.cpp.

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

Referenced by Importer_NS::ImportDriver::importGeoTable(), and runMultipleStatements().

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

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

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

331  {
332  CHECK(import_stmt);
333  import_stmt->execute(*session_info_);
334 }
void execute(const Catalog_Namespace::SessionInfo &session) override
CHECK(cgen_state)
std::shared_ptr< Catalog_Namespace::SessionInfo > session_info_
Definition: QueryRunner.h:188

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

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

301  {
302  std::vector<std::shared_ptr<ResultSet>> results;
303  // TODO: Need to properly handle escaped semicolons instead of doing a naive split().
304  auto fields = split(sql, ";");
305  for (const auto& field : fields) {
306  auto text = strip(field) + ";";
307  if (text == ";") {
308  continue;
309  }
310  // TODO: Maybe remove this redundant parsing after enhancing Parser::Stmt?
311  SQLParser parser;
312  std::list<std::unique_ptr<Parser::Stmt>> parse_trees;
313  std::string last_parsed;
314  CHECK_EQ(parser.parse(text, parse_trees, last_parsed), 0);
315  CHECK_EQ(parse_trees.size(), size_t(1));
316  auto stmt = parse_trees.front().get();
317  Parser::DDLStmt* ddl = dynamic_cast<Parser::DDLStmt*>(stmt);
318  Parser::DMLStmt* dml = dynamic_cast<Parser::DMLStmt*>(stmt);
319  if (ddl != nullptr && dml == nullptr) {
320  runDDLStatement(text);
321  results.push_back(nullptr);
322  } else if (ddl == nullptr && dml != nullptr) {
323  results.push_back(runSQL(text, dt, true, true));
324  } else {
325  throw std::runtime_error("Unexpected SQL statement type: " + text);
326  }
327  }
328  return results;
329 }
#define CHECK_EQ(x, y)
Definition: Logger.h:198
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:

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

References CHECK(), create_query_state(), RelAlgExecutor::executeRelAlgQuery(), 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(), session_info_, and STDLOG.

Referenced by runSQL().

422  {
425  auto query_state = create_query_state(session_info_, query_str);
426  auto stdlog = STDLOG(query_state);
428  return run_select_query_with_filter_push_down(query_state->createQueryStateProxy(),
429  device_type,
430  hoist_literals,
431  allow_loop_joins,
432  just_explain,
434  }
435 
436  const auto& cat = session_info_->getCatalog();
437  auto executor = Executor::getExecutor(cat.getCurrentDB().dbId);
438  CompilationOptions co = {
439  device_type, true, ExecutorOptLevel::LoopStrengthReduction, false};
441  true,
442  just_explain,
443  allow_loop_joins,
444  false,
445  false,
446  false,
447  false,
448  10000,
449  false,
450  false,
452  auto calcite_mgr = cat.getCalciteMgr();
453  const auto query_ra = calcite_mgr
454  ->process(query_state->createQueryStateProxy(),
455  pg_shim(query_str),
456  {},
457  true,
458  false,
459  false)
460  .plan_result;
461  RelAlgExecutor ra_executor(executor.get(), cat);
462  return ra_executor.executeRelAlgQuery(query_ra, co, eo, nullptr);
463 }
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(),::QueryRenderer::QueryRenderManager *render_manager=nullptr)
Definition: Execute.cpp:127
bool g_enable_columnar_output
Definition: Execute.cpp:86
static SysCatalog & instance()
Definition: SysCatalog.h:257
CHECK(cgen_state)
double g_gpu_mem_limit_percent
Definition: QueryRunner.cpp:44
std::shared_ptr< Catalog_Namespace::SessionInfo > session_info_
Definition: QueryRunner.h:188
static std::shared_ptr< query_state::QueryState > create_query_state(Ts &&...args)
Definition: QueryRunner.h:164
bool g_enable_filter_push_down
Definition: Execute.cpp:82
ExecutionResult executeRelAlgQuery(const std::string &query_ra, const CompilationOptions &co, const ExecutionOptions &eo, RenderInfo *render_info)
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 238 of file QueryRunner.cpp.

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

Referenced by runMultipleStatements().

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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 153 of file QueryRunner.h.

References logger::filename(), and ir_file_writer_.

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

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

Definition at line 191 of file QueryRunner.h.

Referenced by runSQL(), and setIRFilename().

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

Definition at line 186 of file QueryRunner.h.

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

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

Definition at line 161 of file QueryRunner.h.

Referenced by create_query_state().

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

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