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



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

Review comment:
       i extend tests but have no reproducer for this assumption ...

##########
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:
       i extend tests but they still ok.




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


Reply via email to