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


##########
core/src/main/java/org/apache/calcite/rel/core/JoinInfo.java:
##########
@@ -66,8 +66,36 @@ public static JoinInfo of(RelNode left, RelNode right, 
RexNode condition) {
     final List<RexNode> nonEquiList = new ArrayList<>();
     RelOptUtil.splitJoinCondition(left, right, condition, leftKeys, rightKeys,
         filterNulls, nonEquiList);
-    return new JoinInfo(ImmutableIntList.copyOf(leftKeys),
-        ImmutableIntList.copyOf(rightKeys), ImmutableList.copyOf(nonEquiList));
+
+    /**
+     * In join implementation when the condition is equality (=),
+     * we filter out nulls prior to the join. If the condition is
+     * `x IS NOT DISTINCT FROM y`, the leftKeys={x}, rightKeys={y},
+     * filterNulls={false}. And then {@link 
EnumerableHashJoin#implementHashJoin}
+     * will use this JoinInfo to generate equi and non-equi condition,
+     * the filterNulls is ignored. We should keep `IS NOT DISTINCT FROM`
+     * in nonEquiConditions and remove x in leftKeys and y in rightKeys.
+     */
+    assert leftKeys.size() == filterNulls.size();
+    final List<Integer> leftKeysRewritten = new ArrayList<>();
+    final List<Integer> rightKeysRewritten = new ArrayList<>();
+    final List<RexNode> nonEquiListRewritten = new ArrayList<>();
+    nonEquiListRewritten.addAll(nonEquiList);
+    for (int i = 0; i < filterNulls.size(); i++) {
+      if (filterNulls.get(i)) {
+        leftKeysRewritten.add(leftKeys.get(i));
+        rightKeysRewritten.add(rightKeys.get(i));
+      } else {
+        nonEquiListRewritten.add(
+            // Until IsNotDistinctFromImplementor is implemented,

Review Comment:
   Previously mentioned in 
[CALCITE-6902](https://issues.apache.org/jira/browse/CALCITE-6902) that 
IsNotDistinctFromImplementor is temporarily not implemented, so I think it's 
time to implement it. I will try to implement an IsNotDistinctFromImplementor.



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