OmniSciDB  1dac507f6e
 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 <stdexcept>
32 #include <unordered_map>
33 #include <vector>
34 
36  size_t val;
37  bool unknown;
38 };
39 
41  int64_t key;
42  size_t val;
43  bool unknown;
44 
45  bool operator<(const SpeculativeTopNEntry& that) const { return val < that.val; }
46  bool operator>(const SpeculativeTopNEntry& that) const { return val > that.val; }
47 };
48 
49 class Executor;
51 class ResultSet;
52 struct RelAlgExecutionUnit;
53 class RowSetMemoryOwner;
54 namespace Analyzer {
55 class Expr;
56 } // namespace Analyzer
57 
59  public:
61 
62  SpeculativeTopNMap(const ResultSet& rows,
63  const std::vector<Analyzer::Expr*>& target_exprs,
64  const size_t truncate_n);
65 
66  void reduce(SpeculativeTopNMap& that);
67 
68  std::shared_ptr<ResultSet> asRows(const RelAlgExecutionUnit& ra_exe_unit,
69  std::shared_ptr<RowSetMemoryOwner> row_set_mem_owner,
71  const Executor* executor,
72  const size_t top_n,
73  const bool desc) const;
74 
75  private:
76  std::unordered_map<int64_t, SpeculativeTopNVal> map_;
77  size_t unknown_;
78 };
79 
80 class SpeculativeTopNFailed : public std::runtime_error {
81  public:
82  SpeculativeTopNFailed() : std::runtime_error("SpeculativeTopNFailed"){};
83 };
84 
86  public:
87  void add(const std::shared_ptr<Analyzer::Expr> expr, const bool desc);
88  bool contains(const std::shared_ptr<Analyzer::Expr> expr, const bool desc) const;
89 
90  private:
91  std::vector<std::pair<std::shared_ptr<Analyzer::Expr>, bool>> blacklist_;
92 };
93 
95 
96 #endif // QUERYENGINE_SPECULATIVETOPN_H
void reduce(SpeculativeTopNMap &that)
bool contains(const std::shared_ptr< Analyzer::Expr > expr, const bool desc) const
bool unknown
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
int64_t key
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
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_