OmniSciDB  c0231cc57d
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
InputDescriptors.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 
17 #ifndef QUERYENGINE_INPUTDESCRIPTORS_H
18 #define QUERYENGINE_INPUTDESCRIPTORS_H
19 
20 #include "../Catalog/TableDescriptor.h"
21 #include "Logger/Logger.h"
22 #include "Shared/toString.h"
23 
24 #include <memory>
25 
26 enum class InputSourceType { TABLE, RESULT };
27 
29  public:
30  InputDescriptor(const int table_id, const int nest_level)
31  : table_id_(table_id), nest_level_(nest_level) {}
32 
33  bool operator==(const InputDescriptor& that) const {
34  return table_id_ == that.table_id_ && nest_level_ == that.nest_level_;
35  }
36 
37  int getTableId() const { return table_id_; }
38 
39  int getNestLevel() const { return nest_level_; }
40 
43  }
44 
45  size_t hash() const {
46  static_assert(sizeof(table_id_) + sizeof(nest_level_) <= sizeof(size_t));
47  return static_cast<size_t>(table_id_) << 8 * sizeof(nest_level_) |
48  static_cast<size_t>(nest_level_);
49  }
50 
51  std::string toString() const {
52  return ::typeName(this) + "(table_id=" + std::to_string(table_id_) +
53  ", nest_level=" + std::to_string(nest_level_) + ")";
54  }
55 
56  private:
57  int table_id_;
59 };
60 
61 inline std::ostream& operator<<(std::ostream& os, InputDescriptor const& id) {
62  return os << "InputDescriptor(table_id(" << id.getTableId() << "),nest_level("
63  << id.getNestLevel() << "))";
64 }
65 
66 class InputColDescriptor final {
67  public:
68  InputColDescriptor(const int col_id, const int table_id, const int nest_level)
69  : col_id_(col_id), input_desc_(table_id, nest_level) {}
70 
71  bool operator==(const InputColDescriptor& that) const {
72  return col_id_ == that.col_id_ && input_desc_ == that.input_desc_;
73  }
74 
75  int getColId() const { return col_id_; }
76 
77  const InputDescriptor& getScanDesc() const { return input_desc_; }
78 
79  size_t hash() const {
80  return input_desc_.hash() ^ (static_cast<size_t>(col_id_) << 16);
81  }
82 
83  std::string toString() const {
84  return ::typeName(this) + "(col_id=" + std::to_string(col_id_) +
85  ", input_desc=" + ::toString(input_desc_) + ")";
86  }
87 
88  private:
89  const int col_id_;
91 };
92 
93 inline std::ostream& operator<<(std::ostream& os, InputColDescriptor const& icd) {
94  return os << "InputColDescriptor(col_id(" << icd.getColId() << ")," << icd.getScanDesc()
95  << ')';
96 }
97 
98 // For printing RelAlgExecutionUnit::input_col_descs
99 inline std::ostream& operator<<(std::ostream& os,
100  std::shared_ptr<const InputColDescriptor> const& icd) {
101  return os << *icd;
102 }
103 
104 namespace std {
105 template <>
106 struct hash<InputColDescriptor> {
107  size_t operator()(const InputColDescriptor& input_col_desc) const {
108  return input_col_desc.hash();
109  }
110 };
111 
112 // Used by hash<std::shared_ptr<const InputColDescriptor>>.
113 template <>
114 struct hash<const InputColDescriptor*> {
115  size_t operator()(const InputColDescriptor* input_col_desc) const {
116  CHECK(input_col_desc);
117  return input_col_desc->hash();
118  }
119 };
120 
121 template <>
122 struct equal_to<shared_ptr<const InputColDescriptor>> {
123  bool operator()(shared_ptr<const InputColDescriptor> const& lhs,
124  shared_ptr<const InputColDescriptor> const& rhs) const {
125  CHECK(lhs && rhs);
126  return *lhs == *rhs;
127  }
128 };
129 } // namespace std
130 
131 #endif // QUERYENGINE_INPUTDESCRIPTORS_H
InputColDescriptor(const int col_id, const int table_id, const int nest_level)
size_t operator()(const InputColDescriptor *input_col_desc) const
size_t hash() const
std::ostream & operator<<(std::ostream &os, const SessionInfo &session_info)
Definition: SessionInfo.cpp:57
std::string to_string(char const *&&v)
int getColId() const
size_t operator()(const InputColDescriptor &input_col_desc) const
int getTableId() const
size_t hash() const
InputDescriptor(const int table_id, const int nest_level)
InputSourceType getSourceType() const
bool operator==(const InputColDescriptor &that) const
std::string toString() const
std::string typeName(const T *v)
Definition: toString.h:103
#define CHECK(condition)
Definition: Logger.h:222
bool operator==(const InputDescriptor &that) const
const InputDescriptor input_desc_
InputSourceType
std::string toString() const
int getNestLevel() const
const InputDescriptor & getScanDesc() const
bool operator()(shared_ptr< const InputColDescriptor > const &lhs, shared_ptr< const InputColDescriptor > const &rhs) const