OmniSciDB  a575cb28ea
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
InputDescriptors.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 
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  std::string toString() const {
46  return ::typeName(this) + "(table_id=" + std::to_string(table_id_) +
47  ", nest_level=" + std::to_string(nest_level_) + ")";
48  }
49 
50  private:
51  int table_id_;
53 };
54 
55 inline std::ostream& operator<<(std::ostream& os, InputDescriptor const& id) {
56  return os << "InputDescriptor(table_id(" << id.getTableId() << "),nest_level("
57  << id.getNestLevel() << "))";
58 }
59 
60 namespace std {
61 template <>
62 struct hash<InputDescriptor> {
63  size_t operator()(const InputDescriptor& input_desc) const {
64  return input_desc.getTableId() ^ input_desc.getNestLevel();
65  }
66 };
67 } // namespace std
68 
70  public:
71  InputColDescriptor(const int col_id, const int table_id, const int nest_level)
72  : col_id_(col_id), input_desc_(table_id, nest_level) {}
73 
74  bool operator==(const InputColDescriptor& that) const {
75  return col_id_ == that.col_id_ && input_desc_ == that.input_desc_;
76  }
77 
78  int getColId() const { return col_id_; }
79 
80  const InputDescriptor& getScanDesc() const { return input_desc_; }
81 
82  virtual ~InputColDescriptor() {}
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  hash<InputDescriptor> input_col_desc_hasher;
110  return input_col_desc_hasher(input_col_desc.getScanDesc()) ^
111  static_cast<size_t>(input_col_desc.getColId());
112  }
113 };
114 
115 template <>
116 struct hash<const InputColDescriptor*> {
117  size_t operator()(const InputColDescriptor* input_col_desc) const {
118  hash<InputColDescriptor> input_col_desc_hasher;
119  CHECK(input_col_desc);
120  return input_col_desc_hasher(*input_col_desc);
121  }
122 };
123 
124 template <>
125 struct equal_to<shared_ptr<const InputColDescriptor>> {
126  bool operator()(shared_ptr<const InputColDescriptor> const& lhs,
127  shared_ptr<const InputColDescriptor> const& rhs) const {
128  CHECK(lhs && rhs);
129  return *lhs == *rhs;
130  }
131 };
132 } // namespace std
133 
134 #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
std::ostream & operator<<(std::ostream &os, const SessionInfo &session_info)
Definition: SessionInfo.cpp:53
size_t operator()(const InputDescriptor &input_desc) const
std::string to_string(char const *&&v)
virtual ~InputColDescriptor()
int getColId() const
size_t operator()(const InputColDescriptor &input_col_desc) const
int getTableId() const
InputDescriptor(const int table_id, const int nest_level)
InputSourceType getSourceType() const
bool operator==(const InputColDescriptor &that) const
std::string toString() const
#define CHECK(condition)
Definition: Logger.h:197
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