@@ -68,6 +68,51 @@ void InnerJoinCommutativity::Transform(
68
68
transformed.push_back (result_plan);
69
69
}
70
70
71
+ // /////////////////////////////////////////////////////////////////////////////
72
+ // / InnerJoinAssociativity
73
+ InnerJoinAssociativity::InnerJoinAssociativity () {
74
+ type_ = RuleType::INNER_JOIN_ASSOCIATE;
75
+
76
+ // Create left nested join
77
+ auto left_child = std::make_shared<Pattern>(OpType::InnerJoin);
78
+ left_child->AddChild (std::make_shared<Pattern>(OpType::Leaf));
79
+ left_child->AddChild (std::make_shared<Pattern>(OpType::Leaf));
80
+
81
+ std::shared_ptr<Pattern> right_child (std::make_shared<Pattern>(OpType::Leaf));
82
+
83
+ match_pattern = std::make_shared<Pattern>(OpType::InnerJoin);
84
+ match_pattern->AddChild (left_child);
85
+ match_pattern->AddChild (right_child);
86
+ }
87
+
88
+ // TODO: As far as I know, theres nothing else that needs to be checked
89
+ bool InnerJoinAssociativity::Check (std::shared_ptr<OperatorExpression> expr,
90
+ OptimizeContext *context) const {
91
+ (void )context;
92
+ (void )expr;
93
+ return true ;
94
+ }
95
+
96
+ void InnerJoinAssociativity::Transform (
97
+ std::shared_ptr<OperatorExpression> input,
98
+ std::vector<std::shared_ptr<OperatorExpression>> &transformed,
99
+ UNUSED_ATTRIBUTE OptimizeContext *context) const {
100
+ auto join_op = input->Op ().As <LogicalInnerJoin>();
101
+ auto join_predicates =
102
+ std::vector<AnnotatedExpression>(join_op->join_predicates );
103
+ auto result_plan = std::make_shared<OperatorExpression>(
104
+ LogicalInnerJoin::make (join_predicates));
105
+ std::vector<std::shared_ptr<OperatorExpression>> children = input->Children ();
106
+ PL_ASSERT (children.size () == 2 );
107
+ LOG_TRACE (
108
+ " Reorder left child with op %s and right child with op %s for inner join" ,
109
+ children[0 ]->Op ().GetName ().c_str (), children[1 ]->Op ().GetName ().c_str ());
110
+ result_plan->PushChild (children[1 ]);
111
+ result_plan->PushChild (children[0 ]);
112
+
113
+ transformed.push_back (result_plan);
114
+ }
115
+
71
116
// ===--------------------------------------------------------------------===//
72
117
// Implementation rules
73
118
// ===--------------------------------------------------------------------===//
0 commit comments