OmniSciDB  04ee39c94c
QueryRunner::QueryRunner Class Reference

#include <QueryRunner.h>

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

Public Member Functions

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 ()
 

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

Protected Attributes

std::unique_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 68 of file QueryRunner.h.

Constructor & Destructor Documentation

◆ ~QueryRunner()

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

Definition at line 153 of file QueryRunner.h.

References session.

153 {}

◆ 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 112 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, Catalog_Namespace::SysCatalog::instance(), Catalog_Namespace::UserMetadata::isSuper, OMNISCI_DEFAULT_DB, Catalog_Namespace::UserMetadata::passwd_hash, register_signal_handler(), session, Catalog_Namespace::Catalog::set(), logger::set_once_fatal_func(), anonymous_namespace{DBObjectPrivilegesTest.cpp}::sys_cat, anonymous_namespace{DBObjectPrivilegesTest.cpp}::user, and Catalog_Namespace::UserMetadata::userId.

123  {
124  boost::filesystem::path base_path{db_path};
125  CHECK(boost::filesystem::exists(base_path));
126  auto system_db_file = base_path / "mapd_catalogs" / OMNISCI_DEFAULT_DB;
127  CHECK(boost::filesystem::exists(system_db_file));
128  auto data_dir = base_path / "mapd_data";
131 
134  g_calcite = std::make_shared<Calcite>(-1, CALCITEPORT, db_path, 1024, "", udf_filename);
135  ExtensionFunctionsWhitelist::add(g_calcite->getExtensionFunctionWhitelist());
136  if (!udf_filename.empty()) {
137  ExtensionFunctionsWhitelist::addUdfs(g_calcite->getUserDefinedFunctionWhitelist());
138  }
139 
140  if (std::is_same<CudaBuildSelector, PreprocessorFalse>::value) {
141  uses_gpus = false;
142  }
143  MapDParameters mapd_params;
144  mapd_params.gpu_buffer_mem_bytes = max_gpu_mem;
145  mapd_params.aggregator = !leaf_servers.empty();
146 
147  auto data_mgr = std::make_shared<Data_Namespace::DataMgr>(
148  data_dir.string(), mapd_params, uses_gpus, -1, 0, reserved_gpu_mem);
149 
151 
152  sys_cat.init(base_path.string(),
153  data_mgr,
154  {},
155  g_calcite,
156  false,
157  mapd_params.aggregator,
158  string_servers);
159 
160  if (create_user) {
161  if (!sys_cat.getMetadataForUser(user_name, user)) {
162  sys_cat.createUser(user_name, passwd, false, "");
163  }
164  }
165  CHECK(sys_cat.getMetadataForUser(user_name, user));
166  CHECK(bcrypt_checkpw(passwd.c_str(), user.passwd_hash.c_str()) == 0);
167 
168  if (create_db) {
169  if (!sys_cat.getMetadataForDB(db_name, db)) {
170  sys_cat.createDatabase(db_name, user.userId);
171  }
172  }
173  CHECK(sys_cat.getMetadataForDB(db_name, db));
174  CHECK(user.isSuper || (user.userId == db.dbOwner));
175  auto cat = std::make_shared<Catalog_Namespace::Catalog>(
176  base_path.string(), db, data_mgr, string_servers, g_calcite, create_db);
177  Catalog_Namespace::Catalog::set(cat->getCurrentDB().dbName, cat);
178  session_info_ = std::make_unique<Catalog_Namespace::SessionInfo>(
179  cat, user, ExecutorDeviceType::GPU, "");
180 }
static void addUdfs(const std::string &json_func_sigs)
#define CALCITEPORT
Definition: QueryRunner.cpp:40
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:287
static SysCatalog & instance()
Definition: SysCatalog.h:240
const std::string OMNISCI_DEFAULT_DB
Definition: SysCatalog.h:58
static void set(const std::string &dbName, std::shared_ptr< Catalog > cat)
Definition: Catalog.cpp:2984
void register_signal_handler(int signum, void(*handler)(int))
Definition: MapDServer.cpp:100
std::shared_ptr< Calcite > g_calcite
Definition: QueryRunner.cpp:50
std::unique_ptr< Catalog_Namespace::SessionInfo > session_info_
Definition: QueryRunner.h:177
#define CHECK(condition)
Definition: Logger.h:187
+ Here is the call graph for this function:

Member Function Documentation

◆ clearCpuMemory()

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

Definition at line 205 of file QueryRunner.cpp.

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

Referenced by TEST().

205  {
208 }
static void clearMemory(const Data_Namespace::MemoryLevel memory_level)
Definition: Execute.cpp:155
static SysCatalog & instance()
Definition: SysCatalog.h:240
#define CHECK(condition)
Definition: Logger.h:187
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ clearGpuMemory()

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

Definition at line 200 of file QueryRunner.cpp.

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

200  {
203 }
static void clearMemory(const Data_Namespace::MemoryLevel memory_level)
Definition: Execute.cpp:155
static SysCatalog & instance()
Definition: SysCatalog.h:240
#define CHECK(condition)
Definition: Logger.h:187
+ Here is the call graph for this function:

◆ get()

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

Definition at line 115 of file QueryRunner.h.

Referenced by assert_grants(), BODY_F(), check_grant_access(), anonymous_namespace{ExecuteTest.cpp}::choose_shard_count(), anonymous_namespace{TopKTest.cpp}::SQLiteComparator::compare_arrow_output(), anonymous_namespace{ExecuteTest.cpp}::SQLiteComparator::compare_arrow_output(), anonymous_namespace{UpdelStorageTest.cpp}::compare_row(), anonymous_namespace{ExecuteTest.cpp}::create_and_populate_tables(), create_dashboards(), create_tables(), create_views(), anonymous_namespace{UpdelStorageTest.cpp}::delete_and_immediately_vacuum_rows(), anonymous_namespace{UpdelStorageTest.cpp}::delete_and_vacuum_varlen_rows(), DashboardObject::drop_dashboards(), drop_dashboards(), drop_tables(), drop_views(), anonymous_namespace{BumpAllocatorTest.cpp}::get_gpu_info(), anonymous_namespace{ExecuteTest.cpp}::import_array_test(), anonymous_namespace{AlterColumnTest.cpp}::import_table_file(), anonymous_namespace{UpdelStorageTest.cpp}::import_table_file(), anonymous_namespace{ImportTest.cpp}::import_test_common_geo(), anonymous_namespace{ImportTest.cpp}::import_test_geofile_importer(), anonymous_namespace{StoragePerfTest.cpp}::load_data_for_thread_test_2(), anonymous_namespace{StoragePerfTest.cpp}::load_data_test(), main(), anonymous_namespace{PlanTest.cpp}::plan_dml(), anonymous_namespace{UpdelStorageTest.cpp}::prepare_table_for_delete(), anonymous_namespace{CalciteOptimizeTest.cpp}::run_ddl_statement(), anonymous_namespace{ComputeMetadataTest.cpp}::run_ddl_statement(), anonymous_namespace{UpdateMetadataTest.cpp}::run_ddl_statement(), anonymous_namespace{DBObjectPrivilegesTest.cpp}::run_ddl_statement(), anonymous_namespace{TopKTest.cpp}::run_ddl_statement(), anonymous_namespace{AlterColumnTest.cpp}::run_ddl_statement(), anonymous_namespace{PlanTest.cpp}::run_ddl_statement(), anonymous_namespace{StoragePerfTest.cpp}::run_ddl_statement(), anonymous_namespace{StorageTest.cpp}::run_ddl_statement(), anonymous_namespace{ImportTest.cpp}::run_ddl_statement(), anonymous_namespace{UpdelStorageTest.cpp}::run_ddl_statement(), anonymous_namespace{UdfTest.cpp}::run_ddl_statement(), anonymous_namespace{ExecuteTest.cpp}::run_ddl_statement(), anonymous_namespace{CtasUpdateTest.cpp}::run_ddl_statement(), anonymous_namespace{ComputeMetadataTest.cpp}::run_multiple_agg(), anonymous_namespace{UpdateMetadataTest.cpp}::run_multiple_agg(), anonymous_namespace{TopKTest.cpp}::run_multiple_agg(), anonymous_namespace{BumpAllocatorTest.cpp}::run_multiple_agg(), anonymous_namespace{UdfTest.cpp}::run_multiple_agg(), anonymous_namespace{ExecuteTest.cpp}::run_multiple_agg(), anonymous_namespace{CtasUpdateTest.cpp}::run_multiple_agg(), anonymous_namespace{ComputeMetadataTest.cpp}::run_op_per_fragment(), anonymous_namespace{AlterColumnTest.cpp}::run_query(), anonymous_namespace{ImportTest.cpp}::run_query(), anonymous_namespace{UpdelStorageTest.cpp}::run_query(), anonymous_namespace{ExecuteTest.cpp}::run_simple_agg(), anonymous_namespace{BumpAllocatorTest.cpp}::setup(), LowGpuBufferMemory::SetUp(), anonymous_namespace{UdfTest.cpp}::SQLTestEnv::SetUp(), LowGpuBufferMemoryCpuRetry::SetUp(), MediumGpuBufferMemory::SetUp(), DashboardObject::setup_dashboards(), anonymous_namespace{StorageTest.cpp}::simple_thread_wrapper(), anonymous_namespace{BumpAllocatorTest.cpp}::skip_tests(), anonymous_namespace{TopKTest.cpp}::skip_tests(), anonymous_namespace{UdfTest.cpp}::skip_tests(), anonymous_namespace{ExecuteTest.cpp}::skip_tests(), sql(), anonymous_namespace{StorageTest.cpp}::storage_test(), anonymous_namespace{StorageTest.cpp}::storage_test_parallel(), LowGpuBufferMemory::TearDown(), LowGpuBufferMemoryCpuRetry::TearDown(), MediumGpuBufferMemory::TearDown(), TEST(), TEST_F(), TEST_P(), testViewPermissions(), and anonymous_namespace{UpdelStorageTest.cpp}::update_common().

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

◆ getCalcite()

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

Definition at line 190 of file QueryRunner.cpp.

References anonymous_namespace{QueryRunner.cpp}::g_calcite.

Referenced by anonymous_namespace{UdfTest.cpp}::SQLTestEnv::SetUp().

190  {
191  // TODO: Embed Calcite shared_ptr ownership in QueryRunner
192  return g_calcite;
193 }
std::shared_ptr< Calcite > g_calcite
Definition: QueryRunner.cpp:50
+ Here is the caller graph for this function:

◆ getCatalog()

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

Definition at line 185 of file QueryRunner.cpp.

References CHECK.

Referenced by BODY_F(), anonymous_namespace{UpdelStorageTest.cpp}::compare_row(), create_tables(), create_views(), anonymous_namespace{UpdelStorageTest.cpp}::delete_and_immediately_vacuum_rows(), anonymous_namespace{UpdelStorageTest.cpp}::delete_and_vacuum_varlen_rows(), drop_tables(), drop_views(), anonymous_namespace{BumpAllocatorTest.cpp}::get_gpu_info(), main(), anonymous_namespace{ComputeMetadataTest.cpp}::run_op_per_fragment(), TEST(), TEST_F(), and TEST_P().

185  {
187  return session_info_->get_catalog_ptr();
188 }
std::unique_ptr< Catalog_Namespace::SessionInfo > session_info_
Definition: QueryRunner.h:177
#define CHECK(condition)
Definition: Logger.h:187
+ Here is the caller graph for this function:

◆ getLoader()

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

Definition at line 325 of file QueryRunner.cpp.

Referenced by anonymous_namespace{ExecuteTest.cpp}::import_array_test().

326  {
327  auto cat = getCatalog();
328  return std::make_unique<Importer_NS::Loader>(*cat, td);
329 }
std::shared_ptr< Catalog_Namespace::Catalog > getCatalog() const
+ Here is the caller graph for this function:

◆ getSession()

Catalog_Namespace::SessionInfo* QueryRunner::QueryRunner::getSession ( ) const
inline

Definition at line 124 of file QueryRunner.h.

Referenced by assert_grants(), check_grant_access(), anonymous_namespace{ExecuteTest.cpp}::choose_shard_count(), anonymous_namespace{ExecuteTest.cpp}::create_and_populate_tables(), create_dashboards(), DashboardObject::drop_dashboards(), drop_dashboards(), anonymous_namespace{ExecuteTest.cpp}::import_array_test(), DashboardObject::setup_dashboards(), TEST(), TEST_F(), and testViewPermissions().

124 { return session_info_.get(); }
std::unique_ptr< Catalog_Namespace::SessionInfo > session_info_
Definition: QueryRunner.h:177
+ Here is the caller graph for this function:

◆ gpusPresent()

bool QueryRunner::QueryRunner::gpusPresent ( ) const

Definition at line 195 of file QueryRunner.cpp.

References CHECK.

Referenced by anonymous_namespace{BumpAllocatorTest.cpp}::skip_tests(), anonymous_namespace{TopKTest.cpp}::skip_tests(), anonymous_namespace{UdfTest.cpp}::skip_tests(), and anonymous_namespace{ExecuteTest.cpp}::skip_tests().

195  {
197  return session_info_->getCatalog().getDataMgr().gpusPresent();
198 }
std::unique_ptr< Catalog_Namespace::SessionInfo > session_info_
Definition: QueryRunner.h:177
#define CHECK(condition)
Definition: Logger.h:187
+ Here is the caller graph for this function:

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

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

Referenced by main(), anonymous_namespace{BumpAllocatorTest.cpp}::setup(), and anonymous_namespace{UdfTest.cpp}::SQLTestEnv::SetUp().

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

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

References logger::init(), OMNISCI_DEFAULT_DB, OMNISCI_ROOT_USER, Testing::pass, and anonymous_namespace{DBObjectPrivilegesTest.cpp}::user.

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

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

References CHECK, logger::FATAL, and LOG_IF.

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

References reset().

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

◆ parsePlan()

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

Definition at line 67 of file ParserUtils.cpp.

67  {
68  return parsePlanCalcite(query_str);
69 }
Planner::RootPlan * parsePlanCalcite(const std::string &query_str)
Definition: ParserUtils.cpp:48

◆ parsePlanCalcite()

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

Definition at line 48 of file ParserUtils.cpp.

References pg_shim(), and translate_query().

48  {
49  ParserWrapper pw{query_str};
50  if (pw.isOtherExplain() || pw.is_ddl || pw.is_update_dml) {
51  return parsePlanLegacy(query_str);
52  }
53 
54  const auto& cat = session_info_->getCatalog();
55  auto calcite_mgr = cat.getCalciteMgr();
56  const auto query_ra =
57  calcite_mgr->process(*session_info_,
58  pg_shim(query_str),
59  {},
60  true,
61  false,
62  false)
63  .plan_result; // if we want to be able to check plans we may want to calc this
64  return translate_query(query_ra, cat);
65 }
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::unique_ptr< Catalog_Namespace::SessionInfo > session_info_
Definition: QueryRunner.h:177
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(), run-benchmark-import::parser, and anonymous_namespace{UpdateMetadataTest.cpp}::query.

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());
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:195
std::unique_ptr< Catalog_Namespace::SessionInfo > session_info_
Definition: QueryRunner.h:177
#define CHECK(condition)
Definition: Logger.h:187
+ Here is the call graph for this function:

◆ reset()

static void QueryRunner::QueryRunner::reset ( )
inlinestatic

Definition at line 122 of file QueryRunner.h.

Referenced by init(), main(), and anonymous_namespace{UdfTest.cpp}::SQLTestEnv::TearDown().

122 { qr_instance_.reset(nullptr); }
static std::unique_ptr< QueryRunner > qr_instance_
Definition: QueryRunner.h:175
+ Here is the caller graph for this function:

◆ runDDLStatement()

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

Definition at line 210 of file QueryRunner.cpp.

References CHECK, CHECK_EQ, Catalog_Namespace::SysCatalog::instance(), and run-benchmark-import::parser.

Referenced by Importer_NS::ImportDriver::importGeoTable(), anonymous_namespace{CalciteOptimizeTest.cpp}::run_ddl_statement(), anonymous_namespace{ComputeMetadataTest.cpp}::run_ddl_statement(), anonymous_namespace{UpdateMetadataTest.cpp}::run_ddl_statement(), anonymous_namespace{TopKTest.cpp}::run_ddl_statement(), anonymous_namespace{DBObjectPrivilegesTest.cpp}::run_ddl_statement(), anonymous_namespace{AlterColumnTest.cpp}::run_ddl_statement(), anonymous_namespace{PlanTest.cpp}::run_ddl_statement(), anonymous_namespace{StoragePerfTest.cpp}::run_ddl_statement(), anonymous_namespace{StorageTest.cpp}::run_ddl_statement(), anonymous_namespace{ImportTest.cpp}::run_ddl_statement(), anonymous_namespace{UpdelStorageTest.cpp}::run_ddl_statement(), anonymous_namespace{UdfTest.cpp}::run_ddl_statement(), anonymous_namespace{ExecuteTest.cpp}::run_ddl_statement(), anonymous_namespace{CtasUpdateTest.cpp}::run_ddl_statement(), LowGpuBufferMemory::SetUp(), LowGpuBufferMemoryCpuRetry::SetUp(), MediumGpuBufferMemory::SetUp(), LowGpuBufferMemory::TearDown(), LowGpuBufferMemoryCpuRetry::TearDown(), and MediumGpuBufferMemory::TearDown().

210  {
213 
214  auto stmt_str = stmt_str_in;
215  // First remove special chars
216  boost::algorithm::trim_left_if(stmt_str, boost::algorithm::is_any_of("\n"));
217  // Then remove spaces
218  boost::algorithm::trim_left(stmt_str);
219 
220  SQLParser parser;
221  std::list<std::unique_ptr<Parser::Stmt>> parse_trees;
222  std::string last_parsed;
223  CHECK_EQ(parser.parse(stmt_str, parse_trees, last_parsed), 0) << stmt_str_in;
224  CHECK_EQ(parse_trees.size(), size_t(1));
225  auto stmt = parse_trees.front().get();
226  auto ddl = dynamic_cast<Parser::DDLStmt*>(stmt);
227  CHECK(ddl);
228  ddl->execute(*session_info_);
229 }
#define CHECK_EQ(x, y)
Definition: Logger.h:195
static SysCatalog & instance()
Definition: SysCatalog.h:240
std::unique_ptr< Catalog_Namespace::SessionInfo > session_info_
Definition: QueryRunner.h:177
#define CHECK(condition)
Definition: Logger.h:187
+ 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 320 of file QueryRunner.cpp.

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

Referenced by anonymous_namespace{AlterColumnTest.cpp}::import_table_file(), and anonymous_namespace{UpdelStorageTest.cpp}::import_table_file().

320  {
321  CHECK(import_stmt);
322  import_stmt->execute(*session_info_);
323 }
void execute(const Catalog_Namespace::SessionInfo &session) override
std::unique_ptr< Catalog_Namespace::SessionInfo > session_info_
Definition: QueryRunner.h:177
#define CHECK(condition)
Definition: Logger.h:187
+ Here is the call graph for this function:
+ Here is the caller 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 288 of file QueryRunner.cpp.

References CHECK_EQ, field(), run-benchmark-import::parser, split(), and strip().

Referenced by sql().

290  {
291  std::vector<std::shared_ptr<ResultSet>> results;
292  // TODO: Need to properly handle escaped semicolons instead of doing a naive split().
293  auto fields = split(sql, ";");
294  for (const auto& field : fields) {
295  auto text = strip(field) + ";";
296  if (text == ";") {
297  continue;
298  }
299  // TODO: Maybe remove this redundant parsing after enhancing Parser::Stmt?
300  SQLParser parser;
301  std::list<std::unique_ptr<Parser::Stmt>> parse_trees;
302  std::string last_parsed;
303  CHECK_EQ(parser.parse(text, parse_trees, last_parsed), 0);
304  CHECK_EQ(parse_trees.size(), size_t(1));
305  auto stmt = parse_trees.front().get();
306  Parser::DDLStmt* ddl = dynamic_cast<Parser::DDLStmt*>(stmt);
307  Parser::DMLStmt* dml = dynamic_cast<Parser::DMLStmt*>(stmt);
308  if (ddl != nullptr && dml == nullptr) {
309  runDDLStatement(text);
310  results.push_back(nullptr);
311  } else if (ddl == nullptr && dml != nullptr) {
312  results.push_back(runSQL(text, dt, true, true));
313  } else {
314  throw std::runtime_error("Unexpected SQL statement type: " + text);
315  }
316  }
317  return results;
318 }
#define CHECK_EQ(x, y)
Definition: Logger.h:195
auto sql(const std::string &sql_stmts)
std::string strip(const std::string &str)
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)
+ Here is the call graph for this function:
+ Here is the caller 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 399 of file QueryRunner.cpp.

References CHECK, 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(), and QueryRunner::anonymous_namespace{QueryRunner.cpp}::run_select_query_with_filter_push_down().

Referenced by anonymous_namespace{TopKTest.cpp}::SQLiteComparator::compare_arrow_output().

403  {
409  device_type,
410  hoist_literals,
411  allow_loop_joins,
412  just_explain,
414  }
415 
416  const auto& cat = session_info_->getCatalog();
417  auto executor = Executor::getExecutor(cat.getCurrentDB().dbId);
418  CompilationOptions co = {
419  device_type, true, ExecutorOptLevel::LoopStrengthReduction, false};
421  true,
422  just_explain,
423  allow_loop_joins,
424  false,
425  false,
426  false,
427  false,
428  10000,
429  false,
430  false,
432  auto calcite_mgr = cat.getCalciteMgr();
433  const auto query_ra =
434  calcite_mgr->process(*session_info_, pg_shim(query_str), {}, true, false, false)
435  .plan_result;
436  RelAlgExecutor ra_executor(executor.get(), cat);
437  return ra_executor.executeRelAlgQuery(query_ra, co, eo, nullptr);
438 }
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:122
ExecutionResult run_select_query_with_filter_push_down(const std::string &query_str, const std::unique_ptr< Catalog_Namespace::SessionInfo > &session, const ExecutorDeviceType device_type, const bool hoist_literals, const bool allow_loop_joins, const bool just_explain, const bool with_filter_push_down)
bool g_enable_columnar_output
Definition: Execute.cpp:84
static SysCatalog & instance()
Definition: SysCatalog.h:240
bool g_enable_filter_push_down
Definition: Execute.cpp:80
double g_gpu_mem_limit_percent
Definition: QueryRunner.cpp:45
std::unique_ptr< Catalog_Namespace::SessionInfo > session_info_
Definition: QueryRunner.h:177
#define CHECK(condition)
Definition: Logger.h:187
ExecutionResult executeRelAlgQuery(const std::string &query_ra, const CompilationOptions &co, const ExecutionOptions &eo, RenderInfo *render_info)
std::string pg_shim(const std::string &query)
+ Here is the call graph for this function:
+ Here is the caller 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 231 of file QueryRunner.cpp.

References CHECK, CHECK_EQ, Executor::getExecutor(), Catalog_Namespace::SysCatalog::instance(), LOG, LoopStrengthReduction, ParserWrapper::NotDML, run-benchmark-import::result, and logger::WARNING.

Referenced by anonymous_namespace{ExecuteTest.cpp}::SQLiteComparator::compare_arrow_output(), main(), anonymous_namespace{ComputeMetadataTest.cpp}::run_multiple_agg(), anonymous_namespace{UpdateMetadataTest.cpp}::run_multiple_agg(), anonymous_namespace{TopKTest.cpp}::run_multiple_agg(), anonymous_namespace{BumpAllocatorTest.cpp}::run_multiple_agg(), anonymous_namespace{UdfTest.cpp}::run_multiple_agg(), anonymous_namespace{ExecuteTest.cpp}::run_multiple_agg(), anonymous_namespace{CtasUpdateTest.cpp}::run_multiple_agg(), anonymous_namespace{AlterColumnTest.cpp}::run_query(), anonymous_namespace{ImportTest.cpp}::run_query(), anonymous_namespace{UpdelStorageTest.cpp}::run_query(), and anonymous_namespace{ExecuteTest.cpp}::run_simple_agg().

234  {
237 
238  ParserWrapper pw{query_str};
239  if (pw.isCalcitePathPermissable()) {
240  if (ir_file_writer_ && (pw.getDMLType() == ParserWrapper::DMLType::NotDML)) {
241  try {
242  const auto result = runSelectQuery(
243  query_str, device_type, hoist_literals, allow_loop_joins, true);
244  const auto crt_row = result.getRows()->getNextRow(true, true);
245  CHECK_EQ(size_t(1), crt_row.size());
246  const auto scalar_ir = boost::get<ScalarTargetValue>(&crt_row[0]);
247  CHECK(scalar_ir);
248  const auto ir_ns = boost::get<NullableString>(scalar_ir);
249  CHECK(ir_ns);
250  const auto ir_str = boost::get<std::string>(ir_ns);
251  CHECK(ir_str);
252  (*ir_file_writer_)(query_str, *ir_str);
253  } catch (const std::exception& e) {
254  LOG(WARNING) << "Failed to run EXPLAIN on SELECT query: " << query_str << " ("
255  << e.what() << "). Proceeding with query execution.";
256  }
257  }
258  const auto execution_result =
259  runSelectQuery(query_str, device_type, hoist_literals, allow_loop_joins);
260 
261  return execution_result.getRows();
262  }
263 
264  const auto& cat = session_info_->getCatalog();
265  auto executor = Executor::getExecutor(cat.getCurrentDB().dbId);
266 
267  auto plan = std::unique_ptr<Planner::RootPlan>(parsePlan(query_str));
268 
269 #ifdef HAVE_CUDA
270  return executor->execute(plan.get(),
271  *session_info_,
272  hoist_literals,
273  device_type,
275  true,
276  allow_loop_joins);
277 #else
278  return executor->execute(plan.get(),
279  *session_info_,
280  hoist_literals,
281  device_type,
283  false,
284  allow_loop_joins);
285 #endif
286 }
#define CHECK_EQ(x, y)
Definition: Logger.h:195
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:122
#define LOG(tag)
Definition: Logger.h:182
std::unique_ptr< IRFileWriter > ir_file_writer_
Definition: QueryRunner.h:180
static SysCatalog & instance()
Definition: SysCatalog.h:240
std::unique_ptr< Catalog_Namespace::SessionInfo > session_info_
Definition: QueryRunner.h:177
#define CHECK(condition)
Definition: Logger.h:187
Planner::RootPlan * parsePlan(const std::string &query_str)
Definition: ParserUtils.cpp:67
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setIRFilename()

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

Definition at line 149 of file QueryRunner.h.

Referenced by main().

149  {
150  ir_file_writer_ = std::make_unique<IRFileWriter>(filename);
151  }
std::unique_ptr< IRFileWriter > ir_file_writer_
Definition: QueryRunner.h:180
+ Here is the caller graph for this function:

Member Data Documentation

◆ ir_file_writer_

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

Definition at line 180 of file QueryRunner.h.

◆ qr_instance_

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

Definition at line 175 of file QueryRunner.h.

◆ session_info_

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

Definition at line 177 of file QueryRunner.h.

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


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