korlov42 commented on a change in pull request #9143:
URL: https://github.com/apache/ignite/pull/9143#discussion_r649187505



##########
File path: 
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/rel/IgniteMergeJoin.java
##########
@@ -173,24 +184,34 @@ else if (isPrefix(rightCollation.getKeys(), 
joinInfo.rightKeys))// preserve righ
         Map<Integer, Integer> rightToLeft = joinInfo.pairs().stream()
             .collect(Collectors.toMap(p -> p.target, p -> p.source));
 
-        List<Integer> collationLeftPrj = new ArrayList<>();
+        List<Integer> collationLeftPrj = new 
ArrayList<>(collation.getKeys().size());
 
         for (Integer c : collation.getKeys()) {
             collationLeftPrj.add(
                 c >= rightOff ? rightToLeft.get(c - rightOff) : c
             );
         }
 
-        boolean preserveNodeCollation = false;
+        boolean preserveNodeCollation = isPrefix(collationLeftPrj, 
joinInfo.leftKeys);
 
         List<Integer> newLeftCollation, newRightCollation;
 
         Map<Integer, Integer> leftToRight = joinInfo.pairs().stream()
             .collect(Collectors.toMap(p -> p.source, p -> p.target));
 
-        if (isPrefix(collationLeftPrj, joinInfo.leftKeys)) { // preserve 
collation
-            newLeftCollation = new ArrayList<>();
-            newRightCollation = new ArrayList<>();
+        if (joinType == RIGHT || joinType == JoinRelType.FULL) {
+            for (RelFieldCollation field : collation.getFieldCollations()) {
+                if (RelFieldCollation.NullDirection.LAST != 
field.nullDirection) {
+                    preserveNodeCollation = false;
+                    break;
+                }
+            }
+        }
+
+        // we can`t preserve collation in case of full/right joins.
+        if (preserveNodeCollation) { // preserve collation
+            newLeftCollation = new ArrayList<>(collation.getKeys().size());
+            newRightCollation = new ArrayList<>(collation.getKeys().size());
 
             int ind = 0;
             for (Integer c : collation.getKeys()) {

Review comment:
       this piece of code is faulty too. Let's extend the test coverage for 
merge join with different types of collations (asc, desc, nulls last, nulls 
first) and fix all collation propagation related problems within this PR




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

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to