OmniSciDB  72c90bc290
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SpeculativeTopN.h
Go to the documentation of this file.
1 /*
2  * Copyright 2022 HEAVY.AI, 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 
23 #ifndef QUERYENGINE_SPECULATIVETOPN_H
24 #define QUERYENGINE_SPECULATIVETOPN_H
25 
26 #include <cstddef>
27 #include <cstdint>
28 #include <memory>
29 #include <mutex>
30 #include <stdexcept>
31 #include <unordered_map>
32 #include <vector>
33 
35  size_t val;
36  bool unknown;
37 };
38 
40  int64_t key;
41  size_t val;
42  bool unknown;
43 
44  bool operator<(const SpeculativeTopNEntry& that) const { return val < that.val; }
45  bool operator>(const SpeculativeTopNEntry& that) const { return val > that.val; }
46 };
47 
48 class Executor;
50 class ResultSet;
51 struct RelAlgExecutionUnit;
52 class RowSetMemoryOwner;
53 namespace Analyzer {
54 class Expr;
55 } // namespace Analyzer
56 
58  public:
60 
62  const std::vector<Analyzer::Expr*>& target_exprs,
63  const size_t truncate_n);
64 
65  void reduce(SpeculativeTopNMap& that);
66 
67  std::shared_ptr<ResultSet> asRows(const RelAlgExecutionUnit& ra_exe_unit,
68  std::shared_ptr<RowSetMemoryOwner> row_set_mem_owner,
70  const Executor* executor,
71  const size_t top_n,
72  const bool desc) const;
73 
74  private:
75  std::unordered_map<int64_t, SpeculativeTopNVal> map_;
76  size_t unknown_;
77 };
78 
79 class SpeculativeTopNFailed : public std::runtime_error {
80  public:
81  SpeculativeTopNFailed(const std::string& msg)
82  : std::runtime_error("SpeculativeTopNFailed: " + msg)
84 
86  : std::runtime_error("SpeculativeTopNFailed"), failed_during_iteration_(true) {}
87 
89 
90  private:
92 };
93 
95  public:
96  void add(const std::shared_ptr<Analyzer::Expr> expr, const bool desc);
97  bool contains(const std::shared_ptr<Analyzer::Expr> expr, const bool desc) const;
98 
99  private:
100  mutable std::mutex mutex_;
101  std::vector<std::pair<std::shared_ptr<Analyzer::Expr>, bool>> blacklist_;
102 };
103 
105 
106 #endif // QUERYENGINE_SPECULATIVETOPN_H
void reduce(SpeculativeTopNMap &that)
bool contains(const std::shared_ptr< Analyzer::Expr > expr, const bool desc) const
bool unknown
SpeculativeTopNFailed(const std::string &msg)
bool use_speculative_top_n(const RelAlgExecutionUnit &ra_exe_unit, const QueryMemoryDescriptor &query_mem_desc)
bool operator>(const SpeculativeTopNEntry &that) const
tuple rows
Definition: report.py:114
bool operator<(const SpeculativeTopNEntry &that) const
size_t val
bool g_enable_smem_group_by true
int64_t key
bool failedDuringIteration() const
std::shared_ptr< ResultSet > asRows(const RelAlgExecutionUnit &ra_exe_unit, std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner, const QueryMemoryDescriptor &query_mem_desc, const Executor *executor, const size_t top_n, const bool desc) const
bool g_enable_watchdog false
Definition: Execute.cpp:80
std::vector< std::pair< std::shared_ptr< Analyzer::Expr >, bool > > blacklist_
void add(const std::shared_ptr< Analyzer::Expr > expr, const bool desc)
std::unordered_map< int64_t, SpeculativeTopNVal > map_