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



##########
File path: core/src/main/java/org/apache/calcite/plan/RelOptUtil.java
##########
@@ -3766,6 +3771,104 @@ private static void fix(List<RexNode> operands, int 
before, int after) {
     }
   }
 
+  /**
+   * Determine whether there is mapping between project input and output 
fields.
+   * Bail out if sort relies on non-trivial expressions.
+   */
+  private static boolean isCollationOnTrivialExpr(
+      List<RexNode> projects, RelDataTypeFactory typeFactory,
+      Mappings.TargetMapping map, RelFieldCollation fc, boolean passDown) {
+    final int index = fc.getFieldIndex();
+    int target = map.getTargetOpt(index);
+    if (target < 0) {
+      return false;
+    }
+
+    final RexNode node = passDown ? projects.get(index) : projects.get(target);
+    if (node.isA(SqlKind.CAST)) {
+      // Check whether it is a monotonic preserving cast
+      final RexCall cast = (RexCall) node;
+      RelFieldCollation newFc = Objects.requireNonNull(RexUtil.apply(map, fc));
+      final RexCallBinding binding =
+          RexCallBinding.create(typeFactory, cast,
+              ImmutableList.of(RelCollations.of(newFc)));
+      if (cast.getOperator().getMonotonicity(binding)
+          == SqlMonotonicity.NOT_MONOTONIC) {
+        return false;
+      }
+    }
+
+    return true;
+  }
+
+  public static Pair<RelTraitSet, List<RelTraitSet>> passThroughTraits(

Review comment:
       Depends on if we want move all most all the code to RelOptUtil, I feel 
like only `isCollationOnTrivialExpr` can be moved to RelOptUtil.
   
   At least `RelOptUtil.passThroughTraits` and `RelOptTuil. deriveTraits` seems 
to me, could encourage people write all `passThroughTraits` and `deriveTraits` 
into `RelOptUtil`, because names here are too generic.
   
   For example, I might ask, why not move implementations in Enumerable Joins 
to `RelOptUtil`, etc.
   

##########
File path: core/src/main/java/org/apache/calcite/plan/RelOptUtil.java
##########
@@ -3766,6 +3771,104 @@ private static void fix(List<RexNode> operands, int 
before, int after) {
     }
   }
 
+  /**
+   * Determine whether there is mapping between project input and output 
fields.
+   * Bail out if sort relies on non-trivial expressions.
+   */
+  private static boolean isCollationOnTrivialExpr(
+      List<RexNode> projects, RelDataTypeFactory typeFactory,
+      Mappings.TargetMapping map, RelFieldCollation fc, boolean passDown) {
+    final int index = fc.getFieldIndex();
+    int target = map.getTargetOpt(index);
+    if (target < 0) {
+      return false;
+    }
+
+    final RexNode node = passDown ? projects.get(index) : projects.get(target);
+    if (node.isA(SqlKind.CAST)) {
+      // Check whether it is a monotonic preserving cast
+      final RexCall cast = (RexCall) node;
+      RelFieldCollation newFc = Objects.requireNonNull(RexUtil.apply(map, fc));
+      final RexCallBinding binding =
+          RexCallBinding.create(typeFactory, cast,
+              ImmutableList.of(RelCollations.of(newFc)));
+      if (cast.getOperator().getMonotonicity(binding)
+          == SqlMonotonicity.NOT_MONOTONIC) {
+        return false;
+      }
+    }
+
+    return true;
+  }
+
+  public static Pair<RelTraitSet, List<RelTraitSet>> passThroughTraits(

Review comment:
       Depends on if we want move all most all the code to RelOptUtil, I feel 
like only `isCollationOnTrivialExpr` can be moved to RelOptUtil.
   
   At least `RelOptUtil.passThroughTraits` and `RelOptTuil. deriveTraits`, 
seems to me, could encourage people write all `passThroughTraits` and 
`deriveTraits` into `RelOptUtil`, because names here are too generic.
   
   For example, I might ask, why not move implementations in Enumerable Joins 
to `RelOptUtil`, etc.
   




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