12
12
13
13
#pragma once
14
14
15
+ #include " optimizer/abstract_node.h"
15
16
#include " optimizer/property_set.h"
16
17
#include " util/hash_util.h"
17
18
21
22
namespace peloton {
22
23
namespace optimizer {
23
24
24
- enum class OpType {
25
- Undefined = 0 ,
26
- // Special match operators
27
- Leaf,
28
- // Logical ops
29
- Get,
30
- LogicalExternalFileGet,
31
- LogicalQueryDerivedGet,
32
- LogicalProjection,
33
- LogicalFilter,
34
- LogicalMarkJoin,
35
- LogicalDependentJoin,
36
- LogicalSingleJoin,
37
- InnerJoin,
38
- LeftJoin,
39
- RightJoin,
40
- OuterJoin,
41
- SemiJoin,
42
- LogicalAggregateAndGroupBy,
43
- LogicalInsert,
44
- LogicalInsertSelect,
45
- LogicalDelete,
46
- LogicalUpdate,
47
- LogicalLimit,
48
- LogicalDistinct,
49
- LogicalExportExternalFile,
50
- // Separate between logical and physical ops
51
- LogicalPhysicalDelimiter,
52
- // Physical ops
53
- DummyScan, /* Dummy Physical Op for SELECT without FROM*/
54
- SeqScan,
55
- IndexScan,
56
- ExternalFileScan,
57
- QueryDerivedScan,
58
- OrderBy,
59
- PhysicalLimit,
60
- Distinct,
61
- InnerNLJoin,
62
- LeftNLJoin,
63
- RightNLJoin,
64
- OuterNLJoin,
65
- InnerHashJoin,
66
- LeftHashJoin,
67
- RightHashJoin,
68
- OuterHashJoin,
69
- Insert,
70
- InsertSelect,
71
- Delete,
72
- Update,
73
- Aggregate,
74
- HashGroupBy,
75
- SortGroupBy,
76
- ExportExternalFile,
77
- };
78
-
79
25
// ===--------------------------------------------------------------------===//
80
26
// Operator Node
81
27
// ===--------------------------------------------------------------------===//
82
28
class OperatorVisitor ;
83
29
84
- struct BaseOperatorNode {
85
- BaseOperatorNode () {}
86
-
87
- virtual ~BaseOperatorNode () {}
88
-
89
- virtual void Accept (OperatorVisitor *v) const = 0;
90
-
91
- virtual std::string GetName () const = 0;
92
-
93
- virtual OpType GetType () const = 0;
94
-
95
- virtual bool IsLogical () const = 0;
96
-
97
- virtual bool IsPhysical () const = 0;
98
-
99
- virtual std::vector<PropertySet> RequiredInputProperties () const {
100
- return {};
101
- }
102
-
103
- virtual hash_t Hash () const {
104
- OpType t = GetType ();
105
- return HashUtil::Hash (&t);
106
- }
107
-
108
- virtual bool operator ==(const BaseOperatorNode &r) {
109
- return GetType () == r.GetType ();
110
- }
111
- };
112
-
113
30
// Curiously recurring template pattern
31
+ // TODO(ncx): this templating would be nice to clean up
114
32
template <typename T>
115
- struct OperatorNode : public BaseOperatorNode {
33
+ struct OperatorNode : public AbstractNode {
34
+ OperatorNode () {}
35
+
36
+ virtual ~OperatorNode () {}
37
+
116
38
void Accept (OperatorVisitor *v) const ;
117
39
118
- std::string GetName () const { return name_; }
40
+ virtual std::string GetName () const { return name_; }
119
41
120
- OpType GetType () const { return type_; }
42
+ virtual OpType GetType () const { return type_; }
121
43
122
44
bool IsLogical () const ;
123
45
@@ -128,32 +50,26 @@ struct OperatorNode : public BaseOperatorNode {
128
50
static OpType type_;
129
51
};
130
52
131
- class Operator {
53
+ class Operator : public AbstractNode {
132
54
public:
133
55
Operator ();
134
56
135
- Operator (BaseOperatorNode *node);
57
+ Operator (AbstractNode *node);
136
58
137
- // Calls corresponding visitor to node
138
59
void Accept (OperatorVisitor *v) const ;
139
60
140
- // Return name of operator
141
61
std::string GetName () const ;
142
62
143
- // Return operator type
144
63
OpType GetType () const ;
145
64
146
- // Operator contains Logical node
147
65
bool IsLogical () const ;
148
66
149
- // Operator contains Physical node
150
67
bool IsPhysical () const ;
151
68
152
69
hash_t Hash () const ;
153
70
154
71
bool operator ==(const Operator &r);
155
72
156
- // Operator contains physical or logical operator node
157
73
bool IsDefined () const ;
158
74
159
75
template <typename T>
@@ -164,8 +80,12 @@ class Operator {
164
80
return nullptr ;
165
81
}
166
82
83
+ static std::string name_;
84
+
85
+ static OpType type_;
86
+
167
87
private:
168
- std::shared_ptr<BaseOperatorNode > node;
88
+ std::shared_ptr<AbstractNode > node;
169
89
};
170
90
171
91
} // namespace optimizer
@@ -174,8 +94,8 @@ class Operator {
174
94
namespace std {
175
95
176
96
template <>
177
- struct hash <peloton::optimizer::BaseOperatorNode > {
178
- typedef peloton::optimizer::BaseOperatorNode argument_type;
97
+ struct hash <peloton::optimizer::AbstractNode > {
98
+ typedef peloton::optimizer::AbstractNode argument_type;
179
99
typedef std::size_t result_type;
180
100
result_type operator ()(argument_type const &s) const { return s.Hash (); }
181
101
};
0 commit comments