amaliujia commented on a change in pull request #2005:
URL: https://github.com/apache/calcite/pull/2005#discussion_r436306942



##########
File path: 
core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableCorrelate.java
##########
@@ -81,6 +87,35 @@ public static EnumerableCorrelate create(
         traitSet, left, right, correlationId, requiredColumns, joinType);
   }
 
+  @Override public Pair<RelTraitSet, List<RelTraitSet>> passThroughTraits(
+      final RelTraitSet required) {
+    final RelCollation collation = required.getCollation();
+    if (collation == null || collation == RelCollations.EMPTY) {
+      return null;
+    }
+
+    // EnumerableCorrelate traits passdown shall only pass through collation 
to left input.
+    // This is because for EnumerableCorrelate always uses left input as the 
outer loop,
+    // thus only left input can preserve ordering.
+
+    for (RelFieldCollation relFieldCollation : collation.getFieldCollations()) 
{
+      // If field collation belongs to right input: bail out.
+      if (relFieldCollation.getFieldIndex() >= 
getLeft().getRowType().getFieldCount()) {
+        return null;
+      }
+    }
+
+    final RelTraitSet passThroughTraitSet = traitSet.replace(collation);
+    return Pair.of(passThroughTraitSet,
+        ImmutableList.of(
+            passThroughTraitSet,
+            passThroughTraitSet.replace(RelCollations.EMPTY)));
+  }
+
+  @Override public DeriveMode getDeriveMode() {
+    return DeriveMode.LEFT_FIRST;
+  }

Review comment:
       Yes. Any collation can be derived from left input. Optimizer can decide 
later if derived collations are useful.




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