OmniSciDB  8a228a1076
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 
23 #include <memory>
24 
25 enum class InputSourceType { TABLE, RESULT };
26 
28  public:
29  InputDescriptor(const int table_id, const int nest_level)
30  : table_id_(table_id), nest_level_(nest_level) {}
31 
32  bool operator==(const InputDescriptor& that) const {
33  return table_id_ == that.table_id_ && nest_level_ == that.nest_level_;
34  }
35 
36  int getTableId() const { return table_id_; }
37 
38  int getNestLevel() const { return nest_level_; }
39 
41  return table_id_ > 0 ? InputSourceType::TABLE : InputSourceType::RESULT;
42  }
43 
44  private:
45  int table_id_;
47 };
48 
49 inline std::ostream& operator<<(std::ostream& os, InputDescriptor const& id) {
50  return os << "InputDescriptor(table_id(" << id.getTableId() << "),nest_level("
51  << id.getNestLevel() << "))";
52 }
53 
54 namespace std {
55 template <>
56 struct hash<InputDescriptor> {
57  size_t operator()(const InputDescriptor& input_desc) const {
58  return input_desc.getTableId() ^ input_desc.getNestLevel();
59  }
60 };
61 } // namespace std
62 
64  public:
65  InputColDescriptor(const int col_id, const int table_id, const int nest_level)
66  : col_id_(col_id), input_desc_(table_id, nest_level) {}
67 
68  bool operator==(const InputColDescriptor& that) const {
69  return col_id_ == that.col_id_ && input_desc_ == that.input_desc_;
70  }
71 
72  int getColId() const { return col_id_; }
73 
74  const InputDescriptor& getScanDesc() const { return input_desc_; }
75 
76  virtual ~InputColDescriptor() {}
77 
78  private:
79  const int col_id_;
81 };
82 
83 inline std::ostream& operator<<(std::ostream& os, InputColDescriptor const& icd) {
84  return os << "InputColDescriptor(col_id(" << icd.getColId() << ")," << icd.getScanDesc()
85  << ')';
86 }
87 
88 // For printing RelAlgExecutionUnit::input_col_descs
89 inline std::ostream& operator<<(std::ostream& os,
90  std::shared_ptr<const InputColDescriptor> const& icd) {
91  return os << *icd;
92 }
93 
94 namespace std {
95 template <>
96 struct hash<InputColDescriptor> {
97  size_t operator()(const InputColDescriptor& input_col_desc) const {
98  hash<InputDescriptor> input_col_desc_hasher;
99  return input_col_desc_hasher(input_col_desc.getScanDesc()) ^
100  static_cast<size_t>(input_col_desc.getColId());
101  }
102 };
103 
104 template <>
105 struct hash<const InputColDescriptor*> {
106  size_t operator()(const InputColDescriptor* input_col_desc) const {
107  hash<InputColDescriptor> input_col_desc_hasher;
108  CHECK(input_col_desc);
109  return input_col_desc_hasher(*input_col_desc);
110  }
111 };
112 
113 template <>
114 struct equal_to<shared_ptr<const InputColDescriptor>> {
115  bool operator()(shared_ptr<const InputColDescriptor> const& lhs,
116  shared_ptr<const InputColDescriptor> const& rhs) const {
117  CHECK(lhs && rhs);
118  return *lhs == *rhs;
119  }
120 };
121 } // namespace std
122 
123 #endif // QUERYENGINE_INPUTDESCRIPTORS_H
size_t operator()(const InputColDescriptor *input_col_desc) const
InputColDescriptor(const int col_id, const int table_id, const int nest_level)
InputSourceType getSourceType() const
int getTableId() const
const InputDescriptor & getScanDesc() const
bool operator==(const InputColDescriptor &that) const
virtual ~InputColDescriptor()
int getNestLevel() const
InputDescriptor(const int table_id, const int nest_level)
bool operator==(const InputDescriptor &that) const
std::ostream & operator<<(std::ostream &os, InputDescriptor const &id)
size_t operator()(const InputColDescriptor &input_col_desc) const
size_t operator()(const InputDescriptor &input_desc) const
#define CHECK(condition)
Definition: Logger.h:197
const InputDescriptor input_desc_
InputSourceType
bool operator()(shared_ptr< const InputColDescriptor > const &lhs, shared_ptr< const InputColDescriptor > const &rhs) const