vldpyatkov commented on code in PR #5393:
URL: https://github.com/apache/calcite/pull/5393#discussion_r4491489271
##########
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) {
Review Comment:
Ok, added.
Map and multiset are already supported in the comparator; it is not a big
issue to add them in the condition.
##########
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:
I've added a comment explaining why collator is unused for composite types.
Collations of nested string types are not yet supported. It works to
implement in the other ticket.
--
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]