Skip to content

Commit 209c46a

Browse files
Newton Xienewtoncx
Newton Xie
authored andcommitted
Adding AbstractNode class.
AbstractNode will provide interface for Operator and eventually AbstractExpressions as well. Note there are a few road blocks before the rest of the rewriter can be changed to cleanly use abstract classes: (1) Similarly abstract OperatorExpressions. (2) We will have to find a good place to hide OpType, which is currently an enum type (cannot be abstracted) and pervades the code base. This may be solved by abstracting at the group level, but will have to look into it. (3) Need to clean up and separate interfaces between AbstractNode, OperatorNode, and Operator classes.
1 parent 484d76d commit 209c46a

File tree

7 files changed

+198
-160
lines changed

7 files changed

+198
-160
lines changed

src/include/optimizer/abstract_node.h

+117
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Peloton
4+
//
5+
// abstract_node.h
6+
//
7+
// Identification: src/include/optimizer/abstract_node.h
8+
//
9+
// Copyright (c) 2015-16, Carnegie Mellon University Database Group
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#pragma once
14+
15+
#include "optimizer/property_set.h"
16+
#include "util/hash_util.h"
17+
18+
#include <memory>
19+
#include <string>
20+
21+
namespace peloton {
22+
namespace optimizer {
23+
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+
//===--------------------------------------------------------------------===//
80+
// Abstract Node
81+
//===--------------------------------------------------------------------===//
82+
//TODO(ncx): dependence on OperatorVisitor
83+
class OperatorVisitor;
84+
85+
struct AbstractNode {
86+
AbstractNode() {}
87+
88+
~AbstractNode() {}
89+
90+
virtual void Accept(OperatorVisitor *v) const = 0;
91+
92+
virtual std::string GetName() const = 0;
93+
94+
// TODO(ncx): problematic dependence on OpType
95+
virtual OpType GetType() const = 0;
96+
97+
virtual bool IsLogical() const = 0;
98+
99+
virtual bool IsPhysical() const = 0;
100+
101+
virtual hash_t Hash() const {
102+
OpType t = GetType();
103+
return HashUtil::Hash(&t);
104+
}
105+
106+
virtual bool operator==(const AbstractNode &r) {
107+
return GetType() == r.GetType();
108+
}
109+
110+
virtual bool IsDefined() const { return node != nullptr; }
111+
112+
private:
113+
std::shared_ptr<AbstractNode> node;
114+
};
115+
116+
} // namespace optimizer
117+
} // namespace peloton

src/include/optimizer/input_column_deriver.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ class InputColumnDeriver : public OperatorVisitor {
100100
* @brief Provide all tuple value expressions needed in the expression
101101
*/
102102
void ScanHelper();
103-
void AggregateHelper(const BaseOperatorNode *);
104-
void JoinHelper(const BaseOperatorNode *op);
103+
void AggregateHelper(const AbstractNode *);
104+
void JoinHelper(const AbstractNode *op);
105105

106106
/**
107107
* @brief Some operators, for example limit, directly pass down column

src/include/optimizer/operator_node.h

+18-98
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#pragma once
1414

15+
#include "optimizer/abstract_node.h"
1516
#include "optimizer/property_set.h"
1617
#include "util/hash_util.h"
1718

@@ -21,103 +22,24 @@
2122
namespace peloton {
2223
namespace optimizer {
2324

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-
7925
//===--------------------------------------------------------------------===//
8026
// Operator Node
8127
//===--------------------------------------------------------------------===//
8228
class OperatorVisitor;
8329

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-
11330
// Curiously recurring template pattern
31+
// TODO(ncx): this templating would be nice to clean up
11432
template <typename T>
115-
struct OperatorNode : public BaseOperatorNode {
33+
struct OperatorNode : public AbstractNode {
34+
OperatorNode() {}
35+
36+
virtual ~OperatorNode() {}
37+
11638
void Accept(OperatorVisitor *v) const;
11739

118-
std::string GetName() const { return name_; }
40+
virtual std::string GetName() const { return name_; }
11941

120-
OpType GetType() const { return type_; }
42+
virtual OpType GetType() const { return type_; }
12143

12244
bool IsLogical() const;
12345

@@ -128,32 +50,26 @@ struct OperatorNode : public BaseOperatorNode {
12850
static OpType type_;
12951
};
13052

131-
class Operator {
53+
class Operator : public AbstractNode {
13254
public:
13355
Operator();
13456

135-
Operator(BaseOperatorNode *node);
57+
Operator(AbstractNode *node);
13658

137-
// Calls corresponding visitor to node
13859
void Accept(OperatorVisitor *v) const;
13960

140-
// Return name of operator
14161
std::string GetName() const;
14262

143-
// Return operator type
14463
OpType GetType() const;
14564

146-
// Operator contains Logical node
14765
bool IsLogical() const;
14866

149-
// Operator contains Physical node
15067
bool IsPhysical() const;
15168

15269
hash_t Hash() const;
15370

15471
bool operator==(const Operator &r);
15572

156-
// Operator contains physical or logical operator node
15773
bool IsDefined() const;
15874

15975
template <typename T>
@@ -164,8 +80,12 @@ class Operator {
16480
return nullptr;
16581
}
16682

83+
static std::string name_;
84+
85+
static OpType type_;
86+
16787
private:
168-
std::shared_ptr<BaseOperatorNode> node;
88+
std::shared_ptr<AbstractNode> node;
16989
};
17090

17191
} // namespace optimizer
@@ -174,8 +94,8 @@ class Operator {
17494
namespace std {
17595

17696
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;
17999
typedef std::size_t result_type;
180100
result_type operator()(argument_type const &s) const { return s.Hash(); }
181101
};

0 commit comments

Comments
 (0)