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



##########
File path: 
core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableProject.java
##########
@@ -86,4 +99,65 @@ 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());
+    if (checkIfSortIsDefinedOnNonTrivalExpr(map, collation)) {
+      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());
+    if (checkIfSortIsDefinedOnNonTrivalExpr(map, collation)) {
+      return null;

Review comment:
       Now it generates a correct plan (sort enforced for top projection).
   
   Also changed this test case to `select a, b*-1, c` pattern for better 
testing.




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