gustavodemorais commented on code in PR #27166:
URL: https://github.com/apache/flink/pull/27166#discussion_r2472294648


##########
flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/plan/stream/sql/MultiJoinTest.java:
##########
@@ -298,6 +298,16 @@ void testFourWayJoinNoCommonJoinKeyRelPlan() {
                         + "LEFT JOIN Shipments s ON p.payment_id = 
s.user_id_3");
     }
 
+    @Test
+    void testFourWayJoinNoCommonJoinKeyRelPlan2() {

Review Comment:
   ```suggestion
       void testFourWayJoinMultipleLocalCommonJoinKeysRelPlan() {
   ```



##########
flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/plan/rules/logical/JoinToMultiJoinRule.java:
##########
@@ -234,11 +236,53 @@ public void onMatch(RelOptRuleCall call) {
                         Pair.left(joinSpecs),
                         projFieldsList,
                         
com.google.common.collect.ImmutableMap.copyOf(newJoinFieldRefCountsMap),
-                        RexUtil.composeConjunction(rexBuilder, 
newPostJoinFilters, true));
+                        RexUtil.composeConjunction(rexBuilder, 
newPostJoinFilters, true),
+                        newCommonJoinKeys);
 
         call.transformTo(multiJoin);
     }
 
+    /**
+     * Creates a Map {join condition -> field names} which has all the 
conditions containing common
+     * join key and all the keys equal to it.
+     *
+     * @param origJoin original Join node
+     * @param left left child of the Join node

Review Comment:
   ```suggestion
        * @param left child of the Join node
   ```



##########
flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/plan/rules/logical/JoinToMultiJoinRule.java:
##########
@@ -234,11 +236,53 @@ public void onMatch(RelOptRuleCall call) {
                         Pair.left(joinSpecs),
                         projFieldsList,
                         
com.google.common.collect.ImmutableMap.copyOf(newJoinFieldRefCountsMap),
-                        RexUtil.composeConjunction(rexBuilder, 
newPostJoinFilters, true));
+                        RexUtil.composeConjunction(rexBuilder, 
newPostJoinFilters, true),
+                        newCommonJoinKeys);
 
         call.transformTo(multiJoin);
     }
 
+    /**
+     * Creates a Map {join condition -> field names} which has all the 
conditions containing common
+     * join key and all the keys equal to it.
+     *
+     * @param origJoin original Join node
+     * @param left left child of the Join node
+     * @return Map {join condition -> field names}
+     */
+    private Map<RexCall, Set<String>> combineJoinKeys(Join origJoin, RelNode 
left) {
+        Map<RexCall, Set<String>> newCondToFieldsMap = 
getCondToFieldsMap(origJoin);
+
+        if (canCombine(left, origJoin)) {
+            final MultiJoin multiJoin = (MultiJoin) left;
+            Map<RexCall, Set<String>> origCondToKeys = 
getCondToFieldsMap(origJoin);
+            Map<RexCall, Set<String>> multiJoinCondToKeys = 
multiJoin.getConditionsToFieldsMap();
+
+            for (Map.Entry<RexCall, Set<String>> origEntry : 
origCondToKeys.entrySet()) {
+                boolean intersects = false;
+                Set<String> origKeys = origEntry.getValue();

Review Comment:
   Can we rename across the rule?
   - origJoin -> newJoin
   - origKeys -> newJoinKeys
   
   Something like this. I think it'd be a bit easier to understand



##########
flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/plan/rules/logical/JoinToMultiJoinRule.java:
##########
@@ -234,11 +236,53 @@ public void onMatch(RelOptRuleCall call) {
                         Pair.left(joinSpecs),
                         projFieldsList,
                         
com.google.common.collect.ImmutableMap.copyOf(newJoinFieldRefCountsMap),
-                        RexUtil.composeConjunction(rexBuilder, 
newPostJoinFilters, true));
+                        RexUtil.composeConjunction(rexBuilder, 
newPostJoinFilters, true),
+                        newCommonJoinKeys);
 
         call.transformTo(multiJoin);
     }
 
+    /**
+     * Creates a Map {join condition -> field names} which has all the 
conditions containing common
+     * join key and all the keys equal to it.

Review Comment:
   Can you add an example of how the map looks like?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to