hsyuan commented on a change in pull request #1985:
URL: https://github.com/apache/calcite/pull/1985#discussion_r431561103



##########
File path: 
core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableProject.java
##########
@@ -86,4 +100,74 @@ public Result implement(EnumerableRelImplementor 
implementor, Prefer pref) {
     // EnumerableCalcRel is always better
     throw new UnsupportedOperationException();
   }
+
+  @Override public Pair<RelTraitSet, List<RelTraitSet>> passThroughTraits(
+      RelTraitSet required) {
+    RelCollation collation = required.getCollation();
+    if (collation == null) {
+      return null;
+    }
+
+    final Mappings.TargetMapping map =
+        RelOptUtil.permutationIgnoreCast(
+            getProjects(), getInput().getRowType());
+
+    for (RelFieldCollation rc : collation.getFieldCollations()) {
+      if (!isCollationOnTrivialExpr(map, rc)) {
+        return null;
+      }
+    }
+
+    final RelCollation newCollation = collation.apply(map);
+    return Pair.of(required, ImmutableList.of(required.replace(newCollation)));
+  }
+
+  @Override public Pair<RelTraitSet, List<RelTraitSet>> deriveTraits(
+      final RelTraitSet childTraits, final int childId) {
+    RelCollation collation = childTraits.getCollation();
+    if (collation == null) {
+      return null;
+    }
+
+    final Mappings.TargetMapping map =
+        RelOptUtil.permutationIgnoreCast(
+            getProjects(), getInput().getRowType());

Review comment:
       You can't use the same mapping. This is used to map parent to child. 
What you want is map child position to parent position.




----------------------------------------------------------------
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:
us...@infra.apache.org


Reply via email to