OmniSciDB  72180abbfe
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SpeculativeTopN.h
Go to the documentation of this file.
1 /*
2  * Copyright 2017 MapD Technologies, 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 
25 #ifndef QUERYENGINE_SPECULATIVETOPN_H
26 #define QUERYENGINE_SPECULATIVETOPN_H
27 
28 #include <cstddef>
29 #include <cstdint>
30 #include <memory>
31 #include <mutex>
32 #include <stdexcept>
33 #include <unordered_map>
34 #include <vector>
35 
37  size_t val;
38  bool unknown;
39 };
40 
42  int64_t key;
43  size_t val;
44  bool unknown;
45 
46  bool operator<(const SpeculativeTopNEntry& that) const { return val < that.val; }
47  bool operator>(const SpeculativeTopNEntry& that) const { return val > that.val; }
48 };
49 
50 class Executor;
52 class ResultSet;
53 struct RelAlgExecutionUnit;
54 class RowSetMemoryOwner;
55 namespace Analyzer {
56 class Expr;
57 } // namespace Analyzer
58 
60  public:
62 
63  SpeculativeTopNMap(const ResultSet& rows,
64  const std::vector<Analyzer::Expr*>& target_exprs,
65  const size_t truncate_n);
66 
67  void reduce(SpeculativeTopNMap& that);
68 
69  std::shared_ptr<ResultSet> asRows(const RelAlgExecutionUnit& ra_exe_unit,
70  std::shared_ptr<RowSetMemoryOwner> row_set_mem_owner,
72  const Executor* executor,
73  const size_t top_n,
74  const bool desc) const;
75 
76  private:
77  std::unordered_map<int64_t, SpeculativeTopNVal> map_;
78  size_t unknown_;
79 };
80 
81 class SpeculativeTopNFailed : public std::runtime_error {
82  public:
83  SpeculativeTopNFailed(const std::string& msg)
84  : std::runtime_error("SpeculativeTopNFailed: " + msg)
86 
88  : std::runtime_error("SpeculativeTopNFailed"), failed_during_iteration_(true) {}
89 
91 
92  private:
94 };
95 
97  public:
98  void add(const std::shared_ptr<Analyzer::Expr> expr, const bool desc);
99  bool contains(const std::shared_ptr<Analyzer::Expr> expr, const bool desc) const;
100 
101  private:
102  mutable std::mutex mutex_;
103  std::vector<std::pair<std::shared_ptr<Analyzer::Expr>, bool>> blacklist_;
104 };
105 
107 
108 #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
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:74
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_