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

Commit 82b8a30

Browse files
author
GustavoAngulo
committed
Formatting
1 parent 86b799e commit 82b8a30

File tree

3 files changed

+42
-42
lines changed

3 files changed

+42
-42
lines changed

src/include/optimizer/rule_impls.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
#include <memory>
1818

19-
2019
namespace peloton {
2120
namespace optimizer {
2221

@@ -45,7 +44,7 @@ class InnerJoinCommutativity : public Rule {
4544

4645
class InnerJoinAssociativity : public Rule {
4746
public:
48-
InnerJoinAssociativity();
47+
InnerJoinAssociativity();
4948

5049
bool Check(std::shared_ptr<OperatorExpression> plan,
5150
OptimizeContext *context) const override;

src/optimizer/rule_impls.cpp

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,15 @@
1212

1313
#include <memory>
1414

15+
#include "catalog/column_catalog.h"
1516
#include "catalog/index_catalog.h"
1617
#include "catalog/table_catalog.h"
17-
#include "catalog/column_catalog.h"
18+
#include "optimizer/operators.h"
19+
#include "optimizer/optimizer_metadata.h"
20+
#include "optimizer/properties.h"
1821
#include "optimizer/rule_impls.h"
1922
#include "optimizer/util.h"
20-
#include "optimizer/operators.h"
2123
#include "storage/data_table.h"
22-
#include "optimizer/properties.h"
23-
#include "optimizer/optimizer_metadata.h"
24-
2524

2625
namespace peloton {
2726
namespace optimizer {
@@ -86,7 +85,7 @@ InnerJoinAssociativity::InnerJoinAssociativity() {
8685
match_pattern->AddChild(right_child);
8786
}
8887

89-
//TODO: As far as I know, theres nothing else that needs to be checked
88+
// TODO: As far as I know, theres nothing else that needs to be checked
9089
bool InnerJoinAssociativity::Check(std::shared_ptr<OperatorExpression> expr,
9190
OptimizeContext *context) const {
9291
(void)context;
@@ -98,10 +97,8 @@ void InnerJoinAssociativity::Transform(
9897
std::shared_ptr<OperatorExpression> input,
9998
std::vector<std::shared_ptr<OperatorExpression>> &transformed,
10099
UNUSED_ATTRIBUTE OptimizeContext *context) const {
101-
102-
103-
// NOTE: Transforms (left JOIN middle) JOIN right -> left JOIN (middle JOIN right)
104-
// Variables are named accordingly to above transformation
100+
// NOTE: Transforms (left JOIN middle) JOIN right -> left JOIN (middle JOIN
101+
// right) Variables are named accordingly to above transformation
105102
auto parent_join = input->Op().As<LogicalInnerJoin>();
106103
std::vector<std::shared_ptr<OperatorExpression>> children = input->Children();
107104
auto child_join = children[0]->Op().As<LogicalInnerJoin>();
@@ -114,7 +111,8 @@ void InnerJoinAssociativity::Transform(
114111

115112
// Get Alias sets
116113
auto &memo = context->metadata->memo;
117-
auto middle_group_id = children[0]->Children()[1]->Op().As<LeafOperator>()->origin_group;
114+
auto middle_group_id =
115+
children[0]->Children()[1]->Op().As<LeafOperator>()->origin_group;
118116
auto right_group_id = children[1]->Op().As<LeafOperator>()->origin_group;
119117

120118
const auto &middle_group_aliases_set =
@@ -123,19 +121,23 @@ void InnerJoinAssociativity::Transform(
123121
memo.GetGroupByID(right_group_id)->GetTableAliases();
124122

125123
// Redistribute predicates
126-
auto parent_join_predicates = std::vector<AnnotatedExpression>(parent_join->join_predicates);
127-
auto child_join_predicates = std::vector<AnnotatedExpression>(child_join->join_predicates);
124+
auto parent_join_predicates =
125+
std::vector<AnnotatedExpression>(parent_join->join_predicates);
126+
auto child_join_predicates =
127+
std::vector<AnnotatedExpression>(child_join->join_predicates);
128128

129129
std::vector<AnnotatedExpression> predicates;
130-
predicates.insert(predicates.end(), parent_join_predicates.begin(), parent_join_predicates.end());
131-
predicates.insert(predicates.end(), child_join_predicates.begin(), child_join_predicates.end());
130+
predicates.insert(predicates.end(), parent_join_predicates.begin(),
131+
parent_join_predicates.end());
132+
predicates.insert(predicates.end(), child_join_predicates.begin(),
133+
child_join_predicates.end());
132134

133135
std::vector<AnnotatedExpression> new_child_join_predicates;
134136
std::vector<AnnotatedExpression> new_parent_join_predicates;
135137

136-
//TODO: This assumes that predicate pushdown has not occured yet, as it will put all non-join predicates into parent join
138+
// TODO: This assumes that predicate pushdown has not occured yet, as it will
139+
// put all non-join predicates into parent join
137140
for (auto predicate : predicates) {
138-
139141
// New child join predicate must contain middle and right group
140142
if (util::IsSubset(middle_group_aliases_set, predicate.table_alias_set) &&
141143
util::IsSubset(right_group_aliases_set, predicate.table_alias_set))
@@ -158,13 +160,11 @@ void InnerJoinAssociativity::Transform(
158160
new_parent_join->PushChild(left);
159161
new_parent_join->PushChild(new_child_join);
160162

161-
162-
LOG_DEBUG(
163-
"Reordered join structured: (%s JOIN %s) JOIN %s",
164-
left->Op().GetName().c_str(), middle->Op().GetName().c_str(), right->Op().GetName().c_str());
163+
LOG_DEBUG("Reordered join structured: (%s JOIN %s) JOIN %s",
164+
left->Op().GetName().c_str(), middle->Op().GetName().c_str(),
165+
right->Op().GetName().c_str());
165166

166167
transformed.push_back(new_parent_join);
167-
168168
}
169169

170170
//===--------------------------------------------------------------------===//
@@ -361,8 +361,8 @@ void GetToIndexScan::Transform(
361361
LOG_TRACE("Value Type: %d",
362362
static_cast<int>(
363363
reinterpret_cast<expression::ConstantValueExpression *>(
364-
expr->GetModifiableChild(1))
365-
->GetValueType()));
364+
expr->GetModifiableChild(1))
365+
->GetValueType()));
366366
} else {
367367
value_list.push_back(
368368
type::ValueFactory::GetParameterOffsetValue(

test/optimizer/optimizer_rule_test.cpp

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,7 @@
1616

1717
#define private public
1818

19-
#include "optimizer/operator_expression.h"
20-
#include "optimizer/operators.h"
21-
#include "optimizer/optimizer.h"
22-
#include "optimizer/rule.h"
23-
#include "optimizer/rule_impls.h"
24-
#include "sql/testing_sql_util.h"
19+
#include "binder/bind_node_visitor.h"
2520
#include "catalog/catalog.h"
2621
#include "common/logger.h"
2722
#include "common/statement.h"
@@ -30,13 +25,17 @@
3025
#include "executor/insert_executor.h"
3126
#include "executor/plan_executor.h"
3227
#include "executor/update_executor.h"
28+
#include "optimizer/operator_expression.h"
29+
#include "optimizer/operators.h"
30+
#include "optimizer/optimizer.h"
31+
#include "optimizer/rule.h"
32+
#include "optimizer/rule_impls.h"
3333
#include "planner/create_plan.h"
3434
#include "planner/delete_plan.h"
3535
#include "planner/insert_plan.h"
3636
#include "planner/update_plan.h"
37+
#include "sql/testing_sql_util.h"
3738
#include "type/value_factory.h"
38-
#include "binder/bind_node_visitor.h"
39-
4039

4140
namespace peloton {
4241
namespace test {
@@ -57,7 +56,6 @@ class OptimizerRuleTests : public PelotonTest {
5756
}
5857
};
5958

60-
6159
TEST_F(OptimizerRuleTests, SimpleCommutativeRuleTest) {
6260
// Build op plan node to match rule
6361
auto left_get = std::make_shared<OperatorExpression>(LogicalGet::make());
@@ -79,7 +77,6 @@ TEST_F(OptimizerRuleTests, SimpleCommutativeRuleTest) {
7977

8078
EXPECT_EQ(output_join->Children()[0], right_get);
8179
EXPECT_EQ(output_join->Children()[1], left_get);
82-
8380
}
8481

8582
TEST_F(OptimizerRuleTests, AssociativeRuleTest) {
@@ -96,8 +93,8 @@ TEST_F(OptimizerRuleTests, AssociativeRuleTest) {
9693
"CREATE TABLE test3(a INT PRIMARY KEY, b INT, c INT);");
9794

9895
auto &peloton_parser = parser::PostgresParser::GetInstance();
99-
auto stmt = peloton_parser.BuildParseTree(
100-
"SELECT * FROM test1, test2, test3");
96+
auto stmt =
97+
peloton_parser.BuildParseTree("SELECT * FROM test1, test2, test3");
10198
auto parse_tree = stmt->GetStatements().at(0).get();
10299
auto predicates = std::vector<expression::AbstractExpression *>();
103100

@@ -119,7 +116,8 @@ TEST_F(OptimizerRuleTests, AssociativeRuleTest) {
119116
std::vector<GroupID> child_groups = {gexpr->GetGroupID()};
120117

121118
auto &memo = optimizer.metadata_.memo;
122-
std::shared_ptr<GroupExpression> head_gexpr = std::make_shared<GroupExpression>(Operator(), child_groups);
119+
std::shared_ptr<GroupExpression> head_gexpr =
120+
std::make_shared<GroupExpression>(Operator(), child_groups);
123121

124122
// Check plan is of structure (left JOIN middle) JOIN right
125123
// Check Parent join
@@ -143,9 +141,11 @@ TEST_F(OptimizerRuleTests, AssociativeRuleTest) {
143141
std::shared_ptr<OptimizeContext> root_context =
144142
std::make_shared<OptimizeContext>(&(optimizer.metadata_), nullptr);
145143

146-
auto task_stack = std::unique_ptr<OptimizerTaskStack>(new OptimizerTaskStack());
144+
auto task_stack =
145+
std::unique_ptr<OptimizerTaskStack>(new OptimizerTaskStack());
147146
optimizer.metadata_.SetTaskPool(task_stack.get());
148-
task_stack->Push(new ApplyRule(group_expr, new InnerJoinAssociativity, root_context));
147+
task_stack->Push(
148+
new ApplyRule(group_expr, new InnerJoinAssociativity, root_context));
149149

150150
while (!task_stack->Empty()) {
151151
auto task = task_stack->Pop();
@@ -163,7 +163,8 @@ TEST_F(OptimizerRuleTests, AssociativeRuleTest) {
163163
LOG_DEBUG("Parent join: OK");
164164

165165
// Check left Get
166-
//TODO: Not sure why left is at index 1, but the (middle JOIN right) is at index 0
166+
// TODO: Not sure why left is at index 1, but the (middle JOIN right) is at
167+
// index 0
167168
left = GetSingleGroupExpression(memo, group_expr, 1);
168169
EXPECT_EQ(OpType::Get, left->Op().GetType());
169170
LOG_DEBUG("Left Leaf: OK");

0 commit comments

Comments
 (0)