Skip to content
This repository was archived by the owner on Sep 27, 2019. It is now read-only.

Commit 3266f29

Browse files
committed
Adding AbstractNodeExpression interface.
1 parent 17de3b9 commit 3266f29

31 files changed

+543
-503
lines changed

src/include/optimizer/abstract_node.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ enum class OpType {
8383
class OperatorVisitor;
8484

8585
struct AbstractNode {
86-
AbstractNode(AbstractNode *node) : node(node) {}
86+
AbstractNode(std::shared_ptr<AbstractNode> node) : node(node) {}
8787

8888
~AbstractNode() {}
8989

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Peloton
4+
//
5+
// abstract_node_expression.h
6+
//
7+
// Identification: src/include/optimizer/abstract_node_expression.h
8+
//
9+
// Copyright (c) 2015-19, Carnegie Mellon University Database Group
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#pragma once
14+
15+
#include "optimizer/abstract_node.h"
16+
17+
#include <memory>
18+
#include <vector>
19+
20+
namespace peloton {
21+
namespace optimizer {
22+
23+
//===--------------------------------------------------------------------===//
24+
// Abstract Node Expression
25+
//===--------------------------------------------------------------------===//
26+
class AbstractNodeExpression {
27+
public:
28+
AbstractNodeExpression() {}
29+
30+
~AbstractNodeExpression() {}
31+
32+
virtual void PushChild(std::shared_ptr<AbstractNodeExpression> child) = 0;
33+
34+
virtual void PopChild() = 0;
35+
36+
virtual const std::vector<std::shared_ptr<AbstractNodeExpression>> &Children() const = 0;
37+
38+
virtual const std::shared_ptr<AbstractNode> Node() const = 0;
39+
40+
virtual const std::string GetInfo() const = 0;
41+
};
42+
43+
} // namespace optimizer
44+
} // namespace peloton

src/include/optimizer/binding.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@
1212

1313
#pragma once
1414

15+
#include "operator_expression.h"
1516
#include "optimizer/operator_node.h"
1617
#include "optimizer/group.h"
1718
#include "optimizer/pattern.h"
19+
1820
#include <map>
1921
#include <tuple>
2022
#include <memory>
21-
#include "operator_expression.h"
2223

2324
namespace peloton {
2425
namespace optimizer {
@@ -37,7 +38,7 @@ class BindingIterator {
3738

3839
virtual bool HasNext() = 0;
3940

40-
virtual std::shared_ptr<OperatorExpression> Next() = 0;
41+
virtual std::shared_ptr<AbstractNodeExpression> Next() = 0;
4142

4243
protected:
4344
Memo &memo_;
@@ -50,7 +51,7 @@ class GroupBindingIterator : public BindingIterator {
5051

5152
bool HasNext() override;
5253

53-
std::shared_ptr<OperatorExpression> Next() override;
54+
std::shared_ptr<AbstractNodeExpression> Next() override;
5455

5556
private:
5657
GroupID group_id_;
@@ -70,16 +71,16 @@ class GroupExprBindingIterator : public BindingIterator {
7071

7172
bool HasNext() override;
7273

73-
std::shared_ptr<OperatorExpression> Next() override;
74+
std::shared_ptr<AbstractNodeExpression> Next() override;
7475

7576
private:
7677
GroupExpression* gexpr_;
7778
std::shared_ptr<Pattern> pattern_;
7879

7980
bool first_;
8081
bool has_next_;
81-
std::shared_ptr<OperatorExpression> current_binding_;
82-
std::vector<std::vector<std::shared_ptr<OperatorExpression>>>
82+
std::shared_ptr<AbstractNodeExpression> current_binding_;
83+
std::vector<std::vector<std::shared_ptr<AbstractNodeExpression>>>
8384
children_bindings_;
8485
std::vector<size_t> children_bindings_pos_;
8586
};

src/include/optimizer/cost_model/default_cost_model.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class DefaultCostModel : public AbstractCostModel {
3434
gexpr_ = gexpr;
3535
memo_ = memo;
3636
txn_ = txn;
37-
gexpr_->Op()->Accept(this);
37+
gexpr_->Node()->Accept(this);
3838
return output_cost_;
3939
}
4040

src/include/optimizer/cost_model/postgres_cost_model.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class PostgresCostModel : public AbstractCostModel {
3939
gexpr_ = gexpr;
4040
memo_ = memo;
4141
txn_ = txn;
42-
gexpr_->Op()->Accept(this);
42+
gexpr_->Node()->Accept(this);
4343
return output_cost_;
4444
};
4545

src/include/optimizer/cost_model/trivial_cost_model.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class TrivialCostModel : public AbstractCostModel {
4141
gexpr_ = gexpr;
4242
memo_ = memo;
4343
txn_ = txn;
44-
gexpr_->Op()->Accept(this);
44+
gexpr_->Node()->Accept(this);
4545
return output_cost_;
4646
};
4747

src/include/optimizer/group_expression.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class GroupExpression {
4646

4747
GroupID GetChildGroupId(int child_idx) const;
4848

49-
std::shared_ptr<AbstractNode> Op() const;
49+
std::shared_ptr<AbstractNode> Node() const;
5050

5151
double GetCost(std::shared_ptr<PropertySet>& requirements) const;
5252

src/include/optimizer/operator_expression.h

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@
22
//
33
// Peloton
44
//
5-
// op_expression.h
5+
// operator_expression.h
66
//
7-
// Identification: src/include/optimizer/op_expression.h
7+
// Identification: src/include/optimizer/operator_expression.h
88
//
9-
// Copyright (c) 2015-16, Carnegie Mellon University Database Group
9+
// Copyright (c) 2015-19, Carnegie Mellon University Database Group
1010
//
1111
//===----------------------------------------------------------------------===//
1212

1313
#pragma once
1414

15+
#include "optimizer/abstract_node_expression.h"
1516
#include "optimizer/operator_node.h"
1617

1718
#include <memory>
@@ -21,25 +22,25 @@ namespace peloton {
2122
namespace optimizer {
2223

2324
//===--------------------------------------------------------------------===//
24-
// Operator Expr
25+
// Operator Expression
2526
//===--------------------------------------------------------------------===//
26-
class OperatorExpression {
27+
class OperatorExpression : public AbstractNodeExpression {
2728
public:
28-
OperatorExpression(Operator op);
29+
OperatorExpression(std::shared_ptr<AbstractNode> node);
2930

30-
void PushChild(std::shared_ptr<OperatorExpression> op);
31+
void PushChild(std::shared_ptr<AbstractNodeExpression> child);
3132

3233
void PopChild();
3334

34-
const std::vector<std::shared_ptr<OperatorExpression>> &Children() const;
35+
const std::vector<std::shared_ptr<AbstractNodeExpression>> &Children() const;
3536

36-
const Operator &Op() const;
37+
const std::shared_ptr<AbstractNode> Node() const;
3738

3839
const std::string GetInfo() const;
3940

4041
private:
41-
Operator op;
42-
std::vector<std::shared_ptr<OperatorExpression>> children;
42+
std::shared_ptr<AbstractNode> node;
43+
std::vector<std::shared_ptr<AbstractNodeExpression>> children;
4344
};
4445

4546
} // namespace optimizer

src/include/optimizer/operator_node.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class Operator : public AbstractNode {
5757
public:
5858
Operator();
5959

60-
Operator(AbstractNode *node);
60+
Operator(std::shared_ptr<AbstractNode> node);
6161

6262
void Accept(OperatorVisitor *v) const;
6363

0 commit comments

Comments
 (0)