suibianwanwank commented on code in PR #3921:
URL: https://github.com/apache/calcite/pull/3921#discussion_r1724709227


##########
core/src/main/java/org/apache/calcite/plan/SubstitutionVisitor.java:
##########
@@ -2169,57 +2145,155 @@ public static boolean equalType(String desc0, 
MutableRel rel0, String desc1,
   }
 
   /**
-   * Check if filter under join can be pulled up,
+   * Check if calc under join can be pulled up,
    * when meeting JoinOnCalc of query unify to Join of target.
    * Working in rules: {@link JoinOnLeftCalcToJoinUnifyRule} <br/>
    * {@link JoinOnRightCalcToJoinUnifyRule} <br/>
    * {@link JoinOnCalcsToJoinUnifyRule} <br/>
    */
-  private static boolean canPullUpFilterUnderJoin(JoinRelType joinType,
-      @Nullable RexNode leftFilterRexNode, @Nullable RexNode 
rightFilterRexNode) {
-    if (joinType == JoinRelType.INNER) {
-      return true;
-    }
-    if (joinType == JoinRelType.LEFT
-        && (rightFilterRexNode == null || rightFilterRexNode.isAlwaysTrue())) {
-      return true;
-    }
-    if (joinType == JoinRelType.RIGHT
-        && (leftFilterRexNode == null || leftFilterRexNode.isAlwaysTrue())) {
-      return true;
+  private static boolean canPullUpCalcUnderJoin(JoinRelType joinType,
+      @Nullable Pair<RexNode, List<RexNode>> qInput0Explained,
+      @Nullable Pair<RexNode, List<RexNode>> qInput1Explained) {
+    if (qInput0Explained != null
+        && joinType.generatesNullsOn(0)
+        && !isCalcStrong(qInput0Explained)) {
+      return false;
     }
-    if (joinType == JoinRelType.FULL
-        && ((rightFilterRexNode == null || rightFilterRexNode.isAlwaysTrue())
-        && (leftFilterRexNode == null || leftFilterRexNode.isAlwaysTrue()))) {
-      return true;
+    if (qInput1Explained != null
+        && joinType.generatesNullsOn(1)
+        && !isCalcStrong(qInput1Explained)) {
+      return false;
     }
-    return false;
+    return true;
+  }
+
+  /** Determines if all projects are strong and the condition is always true. 
*/
+  private static boolean isCalcStrong(Pair<RexNode, List<RexNode>> 
inputExplained) {
+    final RexNode cond = requireNonNull(inputExplained.left, "condition");
+    final List<RexNode> projs = requireNonNull(inputExplained.right, 
"projects");
+    return cond.isAlwaysTrue() && projs.stream().allMatch(STRONG::isNull);
   }
 
   /**
-   * Check if project under join can be pulled up,
-   * when meeting JoinOnCalc of query unify to Join of target.
+
+   */
+
+  /**
+   * Generates project expressions by shifting and adjusting the nullability 
of expressions
+   * based on the provided join targets and inputs.
+   *
+   * <p>Used in the Join rewrite to pull up the calc in query
+   * to the join in mv to ensure operator equivalence. (Already make sure that 
pull up is valid).
    * Working in rules: {@link JoinOnLeftCalcToJoinUnifyRule} <br/>
    * {@link JoinOnRightCalcToJoinUnifyRule} <br/>
    * {@link JoinOnCalcsToJoinUnifyRule} <br/>
+   *
+   * @param query MutableRel of query
+   * @param target MutableRel of target

Review Comment:
   Sounds good, it can be done in other issue



-- 
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