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


##########
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)) {
+          return false;
+        }
+      } else {
+        return false;
+      }
+    }
+    return hasJoinKeyCond;
+  }
+
+  private boolean isJoinKeyCond(RexCall call, int leftFieldCount) {

Review Comment:
   I would call this `isEquiJoinCondition`
   



##########
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) {

Review Comment:
   Frankly, I don't see where "column and constants" is handled
   These checks are fine, but I would have expected to also see a check for 
one-sidedness.
   This can be done with a visitor which checks that the RexInputRefs that 
appear in the expression are not simultaneously from the left and right sides 
(one side or no side (i.e. constants) are fine).



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