You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by GitBox <gi...@apache.org> on 2019/12/25 06:32:19 UTC

[GitHub] [calcite] chunweilei commented on a change in pull request #1688: [CALCITE-3626] Add SortOnCalcToSortUnifyRule in SubstitutionVisitor

chunweilei commented on a change in pull request #1688: [CALCITE-3626] Add SortOnCalcToSortUnifyRule in SubstitutionVisitor
URL: https://github.com/apache/calcite/pull/1688#discussion_r361264735
 
 

 ##########
 File path: core/src/main/java/org/apache/calcite/plan/SubstitutionVisitor.java
 ##########
 @@ -1406,6 +1410,48 @@ private JoinOnCalcsToJoinUnifyRule() {
     }
   }
 
+  /**
+   * A {@link SubstitutionVisitor.UnifyRule} that matches a {@link MutableSort}
+   * which has {@link MutableCalc} as child to a {@link MutableSort}.
+   * We try to pull up the {@link MutableCalc} to top of {@link MutableSort},
+   * then match the {@link MutableSort} in query to {@link MutableSort} in target.
+   */
+  private static class SortOnCalcToSortUnifyRule extends AbstractUnifyRule {
+
+    public static final SortOnCalcToSortUnifyRule INSTANCE =
+        new SortOnCalcToSortUnifyRule();
+
+    private SortOnCalcToSortUnifyRule() {
+      super(operand(MutableSort.class, operand(MutableCalc.class, query(0))),
+          operand(MutableSort.class, target(0)), 1);
+    }
+
+    @Override protected UnifyResult apply(UnifyRuleCall call) {
+      final MutableSort query = (MutableSort) call.query;
+      final MutableCalc qInput = (MutableCalc) query.getInput();
+      final Pair<RexNode, List<RexNode>> qInputExplained = explainCalc(qInput);
+      final List<RexNode> qInputProjs = qInputExplained.right;
+
+      final MutableSort target = (MutableSort) call.target;
+      if (!Objects.equals(query.fetch, target.fetch)
+          || !Objects.equals(query.offset, target.offset)) {
+        return null;
 
 Review comment:
   How about `!(Objects.equals(query.fetch, target.fetch) &&Objects.equals(query.offset, target.offset) )`?

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


With regards,
Apache Git Services