OmniSciDB  0fdbebe030
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
QueryRunner.h
Go to the documentation of this file.
1 /*
2  * Copyright 2019 OmniSci, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef QUERY_RUNNER_H
18 #define QUERY_RUNNER_H
19 
20 #include <fstream>
21 #include <memory>
22 #include <string>
23 
24 #include "Catalog/SessionInfo.h"
25 #include "Catalog/SysCatalog.h"
27 #include "LeafAggregator.h"
30 
31 namespace Catalog_Namespace {
32 class Catalog;
33 struct UserMetadata;
34 } // namespace Catalog_Namespace
35 
36 class ResultSet;
37 class ExecutionResult;
38 
39 namespace Parser {
40 class CopyTableStmt;
41 }
42 
44 
45 namespace Importer_NS {
46 class Loader;
47 }
48 
49 class Calcite;
50 
51 namespace QueryRunner {
52 
53 class QueryRunner {
54  public:
55  static QueryRunner* init(const char* db_path,
56  const std::string& udf_filename = "",
57  const size_t max_gpu_mem = 0, // use all available mem
58  const int reserved_gpu_mem = 256 << 20) {
59  return QueryRunner::init(db_path,
60  std::string{OMNISCI_ROOT_USER},
61  "HyperInteractive",
62  std::string{OMNISCI_DEFAULT_DB},
63  {},
64  {},
65  udf_filename,
66  true,
67  max_gpu_mem,
68  reserved_gpu_mem);
69  }
70 
71  static QueryRunner* init(const char* db_path,
72  const std::vector<LeafHostInfo>& string_servers,
73  const std::vector<LeafHostInfo>& leaf_servers) {
74  return QueryRunner::init(db_path,
75  std::string{OMNISCI_ROOT_USER},
76  "HyperInteractive",
77  std::string{OMNISCI_DEFAULT_DB},
78  string_servers,
79  leaf_servers);
80  }
81 
82  static QueryRunner* init(const char* db_path,
83  const std::string& user,
84  const std::string& pass,
85  const std::string& db_name,
86  const std::vector<LeafHostInfo>& string_servers,
87  const std::vector<LeafHostInfo>& leaf_servers,
88  const std::string& udf_filename = "",
89  bool uses_gpus = true,
90  const size_t max_gpu_mem = 0, // use all available mem
91  const int reserved_gpu_mem = 256 << 20,
92  const bool create_user = false,
93  const bool create_db = false);
94 
95  static QueryRunner* init(std::unique_ptr<Catalog_Namespace::SessionInfo>& session) {
96  qr_instance_.reset(new QueryRunner(std::move(session)));
97  return qr_instance_.get();
98  }
99 
100  static QueryRunner* get() {
101  if (!qr_instance_) {
102  throw std::runtime_error("QueryRunner must be initialized before calling get().");
103  }
104  return qr_instance_.get();
105  }
106 
107  static void reset();
108 
109  std::shared_ptr<Catalog_Namespace::SessionInfo> getSession() const {
110  return session_info_;
111  }
112  std::shared_ptr<Catalog_Namespace::Catalog> getCatalog() const;
113  std::shared_ptr<Calcite> getCalcite() const;
114 
115  bool gpusPresent() const;
116  virtual void clearGpuMemory() const;
117  virtual void clearCpuMemory() const;
118 
119  virtual void runDDLStatement(const std::string&);
120  virtual std::shared_ptr<ResultSet> runSQL(const std::string& query_str,
121  const ExecutorDeviceType device_type,
122  const bool hoist_literals = true,
123  const bool allow_loop_joins = true);
124  virtual ExecutionResult runSelectQuery(const std::string& query_str,
125  const ExecutorDeviceType device_type,
126  const bool hoist_literals,
127  const bool allow_loop_joins,
128  const bool just_explain = false);
129  virtual std::vector<std::shared_ptr<ResultSet>> runMultipleStatements(
130  const std::string&,
131  const ExecutorDeviceType);
132 
133  virtual void runImport(Parser::CopyTableStmt* import_stmt);
134  virtual std::unique_ptr<Importer_NS::Loader> getLoader(const TableDescriptor* td) const;
135 
136  virtual ~QueryRunner() {}
137 
138  QueryRunner(std::unique_ptr<Catalog_Namespace::SessionInfo> session);
139 
141 
142  template <typename... Ts>
143  static std::shared_ptr<query_state::QueryState> create_query_state(Ts&&... args) {
144  return query_states_.create(std::forward<Ts>(args)...);
145  }
146 
147  protected:
148  QueryRunner(const char* db_path,
149  const std::string& user,
150  const std::string& pass,
151  const std::string& db_name,
152  const std::vector<LeafHostInfo>& string_servers,
153  const std::vector<LeafHostInfo>& leaf_servers,
154  const std::string& udf_filename,
155  bool uses_gpus,
156  const size_t max_gpu_mem,
157  const int reserved_gpu_mem,
158  const bool create_user,
159  const bool create_db);
160 
161  static std::unique_ptr<QueryRunner> qr_instance_;
162 
163  std::shared_ptr<Catalog_Namespace::SessionInfo> session_info_;
164 };
165 
166 class ImportDriver : public QueryRunner {
167  public:
168  ImportDriver(std::shared_ptr<Catalog_Namespace::Catalog> cat,
171 
172  void importGeoTable(const std::string& file_path,
173  const std::string& table_name,
174  const bool compression,
175  const bool create_table,
176  const bool explode_collections);
177 };
178 
179 } // namespace QueryRunner
180 
181 #endif // QUERY_RUNNER_H
static query_state::QueryStates query_states_
Definition: QueryRunner.h:140
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)
std::shared_ptr< Catalog_Namespace::SessionInfo > getSession() const
Definition: QueryRunner.h:109
virtual void clearGpuMemory() const
ExecutorDeviceType
virtual std::vector< std::shared_ptr< ResultSet > > runMultipleStatements(const std::string &, const ExecutorDeviceType)
CircleBuffer::value_type create(ARGS &&...args)
Definition: QueryState.h:185
static QueryRunner * init(const char *db_path, const std::vector< LeafHostInfo > &string_servers, const std::vector< LeafHostInfo > &leaf_servers)
Definition: QueryRunner.h:71
static 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)
Definition: QueryRunner.h:55
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)
ResultSet(const std::vector< TargetInfo > &targets, const ExecutorDeviceType device_type, const QueryMemoryDescriptor &query_mem_desc, const std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner, const Executor *executor)
Definition: ResultSet.cpp:94
ImportDriver(std::shared_ptr< Catalog_Namespace::Catalog > cat, const Catalog_Namespace::UserMetadata &user, const ExecutorDeviceType dt=ExecutorDeviceType::GPU)
This file contains the class specification and related data structures for SysCatalog.
void init(LogOptions const &log_opts)
Definition: Logger.cpp:276
const std::string OMNISCI_DEFAULT_DB
Definition: SysCatalog.h:58
QueryRunner(std::unique_ptr< Catalog_Namespace::SessionInfo > session)
virtual void runImport(Parser::CopyTableStmt *import_stmt)
virtual void runDDLStatement(const std::string &)
static std::unique_ptr< QueryRunner > qr_instance_
Definition: QueryRunner.h:161
void importGeoTable(const std::string &file_path, const std::string &table_name, const bool compression, const bool create_table, const bool explode_collections)
const std::string OMNISCI_ROOT_USER
Definition: SysCatalog.h:59
virtual void clearCpuMemory() const
std::shared_ptr< Catalog_Namespace::SessionInfo > session_info_
Definition: QueryRunner.h:163
virtual std::unique_ptr< Importer_NS::Loader > getLoader(const TableDescriptor *td) const
static std::shared_ptr< query_state::QueryState > create_query_state(Ts &&...args)
Definition: QueryRunner.h:143
std::shared_ptr< Calcite > getCalcite() const
static QueryRunner * init(std::unique_ptr< Catalog_Namespace::SessionInfo > &session)
Definition: QueryRunner.h:95
std::shared_ptr< Catalog_Namespace::Catalog > getCatalog() const
specifies the content in-memory of a row in the table metadata table
static unsigned pass
Definition: testing.h:29