xiedeyantu commented on code in PR #4315:
URL: https://github.com/apache/calcite/pull/4315#discussion_r2049729546


##########
core/src/main/java/org/apache/calcite/rel/rules/JoinConditionOrExpansionRule.java:
##########
@@ -140,31 +141,55 @@ private List<RexNode> splitCond(Join join) {
   }
 
   private boolean isValidCond(RexNode node, int leftFieldCount) {
-    if (!(node instanceof RexCall)) {
-      return false;
-    }
+    boolean hasJoinKeyCond = false;
+    List<RexNode> conds = RelOptUtil.conjunctions(node);
+    for (RexNode cond : conds) {
+      if (!(node instanceof RexCall)) {
+        return false;
+      }
 
-    RexCall call = (RexCall) node;
-    SqlKind kind = call.getKind();
-    switch (kind) {
-    case EQUALS:
-    case IS_NOT_DISTINCT_FROM:
-      RexNode left = call.getOperands().get(0);
-      RexNode right = call.getOperands().get(1);
-
-      if (left instanceof RexInputRef && right instanceof RexInputRef) {
-        RexInputRef leftRef = (RexInputRef) left;
-        RexInputRef rightRef = (RexInputRef) right;
-        return (leftRef.getIndex() < leftFieldCount && rightRef.getIndex() >= 
leftFieldCount)
-            || (leftRef.getIndex() >= leftFieldCount && rightRef.getIndex() < 
leftFieldCount);
+      RexCall call = (RexCall) cond;
+      // Checks if the call is valid for use as a join key.
+      if (isJoinKeyCond(call, leftFieldCount)) {
+        hasJoinKeyCond = true;
+        continue;
+      } else if (RexUtil.SubQueryFinder.find(call) != null
+          || RexUtil.containsCorrelation(call)) {
+        // The call does not support sub-queries or correlation yet
+        return false;
       }
+
+      // Check if call is a binary expression.
+      if (call.getOperands().size() == 2) {
+        RexNode left = call.getOperands().get(0);
+        RexNode right = call.getOperands().get(1);
+        if (!(left instanceof RexLiteral) && !(right instanceof RexLiteral)) {

Review Comment:
   @mihaibudiu The check I'm doing here. If it's a binary expression, then 
there must be at least one constant on both sides of it. Does this meet the 
requirements?



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