rubenada commented on code in PR #5393:
URL: https://github.com/apache/calcite/pull/5393#discussion_r4482887144
##########
core/src/main/java/org/apache/calcite/adapter/enumerable/PhysTypeImpl.java:
##########
@@ -544,6 +530,37 @@ private Expression generateComparator(RelCollation
collation,
});
}
+ private static boolean isComposite(RelDataType type) {
+ return type.isStruct() || type.getComponentType() != null;
+ }
+
+ /** ROW and ARRAY sort keys are not Comparable.
+ * Use the same element-wise comparator as the single-key sort path. */
+ private static Expression generateComparison(RelDataType type, String method,
+ Expression left, Expression right, @Nullable Expression collator) {
+ if (isComposite(type)) {
+ final Expression comparison =
+ Expressions.call(
+ Expressions.call(BuiltInMethod.NULLS_COMPARATOR.method,
+ Expressions.constant(method.equals("compareNullsFirst")),
+ Expressions.constant(false)),
+ BuiltInMethod.COMPARATOR_COMPARE.method, left, right);
+ if (method.equals("compareNullsLastForMergeJoin")) {
+ // This call throws BothValuesAreNullException, which merge join
catches
+ // to advance without matching two null keys.
+ return Expressions.condition(
+ Expressions.andAlso(Expressions.equal(left,
Expressions.constant(null)),
+ Expressions.equal(right, Expressions.constant(null))),
+ Expressions.call(Utilities.class, method,
+ Expressions.constant(null, Comparable.class),
+ Expressions.constant(null, Comparable.class)), comparison);
+ }
+ return comparison;
Review Comment:
nit: The collator is silently ignored on the composite path, which I think
is harmless today, because ROW/ARRAY types carry no collation, but a one-line
comment would make the intent explicit.
--
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]