vldpyatkov commented on code in PR #5393:
URL: https://github.com/apache/calcite/pull/5393#discussion_r4507570931
##########
core/src/main/java/org/apache/calcite/adapter/enumerable/PhysTypeImpl.java:
##########
@@ -538,12 +525,55 @@ private Expression generateComparator(RelCollation
collation,
// merge join keys must be sorted in ascending order, nulls last
assert fieldCollation.nullDirection ==
RelFieldCollation.NullDirection.LAST;
assert fieldCollation.getDirection() ==
RelFieldCollation.Direction.ASCENDING;
- return fieldNullable(fieldCollation.getFieldIndex())
+ final int index = fieldCollation.getFieldIndex();
+ // Even a non-null ROW can have NULL fields that prevent a join match.
+ return fieldNullable(index) ||
rowType.getFieldList().get(index).getType().isStruct()
? "compareNullsLastForMergeJoin"
: "compare";
});
}
+ private static boolean isComposite(RelDataType type) {
+ return type.isStruct()
+ || type.getComponentType() != null
+ || type.getSqlTypeName() == SqlTypeName.MAP;
+ }
+
+ /** ROW, ARRAY, MULTISET and MAP 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)) {
+ // Composite types have no collation of their own, so collator is unused
here.
+ final String compositeMethod;
+ switch (method) {
+ case "compare":
+ compositeMethod = "compareComposite";
+ break;
+ case "compareNullsFirst":
+ compositeMethod = "compareCompositeNullsFirst";
+ break;
+ case "compareNullsLast":
+ compositeMethod = "compareCompositeNullsLast";
+ break;
+ case "compareNullsLastForMergeJoin":
+ compositeMethod = "compareCompositeNullsLastForMergeJoin";
+ if (type.isStruct()) {
+ final ParameterExpression row = Expressions.parameter(Object.class,
"row");
Review Comment:
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]