rubenada commented on code in PR #5393:
URL: https://github.com/apache/calcite/pull/5393#discussion_r4495805717
##########
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:
Technically, if `c == 0` then it should be enough to check
`containsNull.apply(v0)` , so we could skip the `containsNull.apply(v1)`; we
could keep it, since it's harmless. In any case, a comment here is probably
worth it, to clarify that "this is a row type with a NULL inside, so we need to
throw the same signal as two null keys to advance without matching"
--
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]