vldpyatkov commented on code in PR #5393:
URL: https://github.com/apache/calcite/pull/5393#discussion_r4507574146


##########
linq4j/src/main/java/org/apache/calcite/linq4j/EnumerableDefaults.java:
##########
@@ -5424,6 +5424,36 @@ private static class BothValuesAreNullException extends 
RuntimeException {
     }
   }
 
+  /** Variant of {@link #compareNullsLastForMergeJoin(Comparable, Comparable, 
Comparator)}
+   * for values that are not {@link Comparable}, such as ROW and ARRAY values.
+   * Throws {@link BothValuesAreNullException} if both values are null. */
+  public static <T> int compareObjectsNullsLastForMergeJoin(@Nullable T v0,
+      @Nullable T v1, Comparator<? super T> comparator) {
+    return compareObjectsNullsLastForMergeJoin(v0, v1, comparator, null);
+  }
+
+  /** Compares merge join keys, optionally rejecting equal keys containing 
NULL fields.
+   * Checks fields only after comparing keys, so unequal keys retain their 
sort order. */
+  public static <T> int compareObjectsNullsLastForMergeJoin(@Nullable T v0,
+      @Nullable T v1, Comparator<? super T> comparator,
+      @Nullable Predicate1<? super T> containsNull) {
+    if (v0 == null && v1 == null) {
+      throw new BothValuesAreNullException();
+    }
+    if (v0 == null) {
+      return 1;
+    }
+    if (v1 == null) {
+      return -1;
+    }
+    final int c = comparator.compare(v0, v1);
+    if (c == 0 && containsNull != null
+        && (containsNull.apply(v0) || containsNull.apply(v1))) {

Review Comment:
   Removed the redundant check of v1 and added a comment



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