OmniSciDB  c1a53651b2
 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 
72  size_t hash() const {
73  return input_desc_.hash() ^ (static_cast<size_t>(col_id_) << 16);
74  }
75 
76  std::string toString() const {
77  return ::typeName(this) + "(col_id=" + std::to_string(col_id_) +
78  ", input_desc=" + ::toString(input_desc_) + ")";
79  }
80 
81  private:
82  const int col_id_;
84 };
85 
86 inline std::ostream& operator<<(std::ostream& os, InputColDescriptor const& icd) {
87  return os << "InputColDescriptor(col_id(" << icd.getColId() << ")," << icd.getScanDesc()
88  << ')';
89 }
90 
91 // For printing RelAlgExecutionUnit::input_col_descs
92 inline std::ostream& operator<<(std::ostream& os,
93  std::shared_ptr<const InputColDescriptor> const& icd) {
94  return os << *icd;
95 }
96 
97 namespace std {
98 template <>
99 struct hash<InputColDescriptor> {
100  size_t operator()(const InputColDescriptor& input_col_desc) const {
101  return input_col_desc.hash();
102  }
103 };
104 
105 // Used by hash<std::shared_ptr<const InputColDescriptor>>.
106 template <>
107 struct hash<const InputColDescriptor*> {
108  size_t operator()(const InputColDescriptor* input_col_desc) const {
109  CHECK(input_col_desc);
110  return input_col_desc->hash();
111  }
112 };
113 
114 template <>
115 struct equal_to<shared_ptr<const InputColDescriptor>> {
116  bool operator()(shared_ptr<const InputColDescriptor> const& lhs,
117  shared_ptr<const InputColDescriptor> const& rhs) const {
118  CHECK(lhs && rhs);
119  return *lhs == *rhs;
120  }
121 };
122 } // namespace std
123 
124 #endif // QUERYENGINE_INPUTDESCRIPTORS_H
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_
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:103
#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