OmniSciDB  72c90bc290
 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/DbObjectKeys.h"
23 #include "Shared/misc.h"
24 #include "Shared/toString.h"
25 
26 #include <memory>
27 
28 enum class InputSourceType { TABLE, RESULT };
29 
31  public:
32  InputDescriptor(int32_t db_id, int32_t table_id, int32_t nest_level)
33  : table_key_(db_id, table_id), nest_level_(nest_level) {}
34 
35  bool operator==(const InputDescriptor& that) const {
36  return table_key_ == that.table_key_ && nest_level_ == that.nest_level_;
37  }
38 
39  const shared::TableKey& getTableKey() const { return table_key_; }
40 
41  int32_t getNestLevel() const { return nest_level_; }
42 
44 
45  size_t hash() const;
46 
47  std::string toString() const;
48 
49  private:
51  int32_t nest_level_;
52 };
53 
54 inline std::ostream& operator<<(std::ostream& os, InputDescriptor const& id) {
55  return os << "InputDescriptor(db_id(" << id.getTableKey().db_id << "), table_id("
56  << id.getTableKey().table_id << "),nest_level(" << id.getNestLevel() << "))";
57 }
58 
59 class InputColDescriptor final {
60  public:
61  InputColDescriptor(int32_t col_id, int32_t table_id, int32_t db_id, int32_t nest_level)
62  : col_id_(col_id), input_desc_(db_id, table_id, nest_level) {}
63 
64  bool operator==(const InputColDescriptor& that) const {
65  return col_id_ == that.col_id_ && input_desc_ == that.input_desc_;
66  }
67 
68  int getColId() const { return col_id_; }
69 
70  const InputDescriptor& getScanDesc() const { return input_desc_; }
71 
74  }
75 
78  }
79 
80  size_t hash() const {
81  return input_desc_.hash() ^ (static_cast<size_t>(col_id_) << 16);
82  }
83 
84  std::string toString() const {
85  return ::typeName(this) + "(col_id=" + std::to_string(col_id_) +
86  ", input_desc=" + ::toString(input_desc_) + ")";
87  }
88 
89  private:
90  const int col_id_;
92 };
93 
94 inline std::ostream& operator<<(std::ostream& os, InputColDescriptor const& icd) {
95  return os << "InputColDescriptor(col_id(" << icd.getColId() << ")," << icd.getScanDesc()
96  << ')';
97 }
98 
99 // For printing RelAlgExecutionUnit::input_col_descs
100 inline std::ostream& operator<<(std::ostream& os,
101  std::shared_ptr<const InputColDescriptor> const& icd) {
102  return os << *icd;
103 }
104 
105 namespace std {
106 template <>
107 struct hash<InputColDescriptor> {
108  size_t operator()(const InputColDescriptor& input_col_desc) const {
109  return input_col_desc.hash();
110  }
111 };
112 
113 // Used by hash<std::shared_ptr<const InputColDescriptor>>.
114 template <>
115 struct hash<const InputColDescriptor*> {
116  size_t operator()(const InputColDescriptor* input_col_desc) const {
117  CHECK(input_col_desc);
118  return input_col_desc->hash();
119  }
120 };
121 
122 template <>
123 struct equal_to<shared_ptr<const InputColDescriptor>> {
124  bool operator()(shared_ptr<const InputColDescriptor> const& lhs,
125  shared_ptr<const InputColDescriptor> const& rhs) const {
126  CHECK(lhs && rhs);
127  return *lhs == *rhs;
128  }
129 };
130 } // namespace std
131 
132 #endif // QUERYENGINE_INPUTDESCRIPTORS_H
shared::ColumnKey getColumnKey() const
int32_t getNestLevel() const
InputColDescriptor(int32_t col_id, int32_t table_id, int32_t db_id, int32_t 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)
shared::TableKey table_key_
shared::TableKey getTableKey() const
int getColId() const
size_t operator()(const InputColDescriptor &input_col_desc) const
size_t hash() const
const shared::TableKey & getTableKey() const
InputSourceType getSourceType() const
bool operator==(const InputColDescriptor &that) const
std::string toString() const
std::string typeName(const T *v)
Definition: toString.h:106
#define CHECK(condition)
Definition: Logger.h:291
bool operator==(const InputDescriptor &that) const
const InputDescriptor input_desc_
InputSourceType
InputDescriptor(int32_t db_id, int32_t table_id, int32_t nest_level)
std::string toString() const
const InputDescriptor & getScanDesc() const
bool operator()(shared_ptr< const InputColDescriptor > const &lhs, shared_ptr< const InputColDescriptor > const &rhs) const