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 2020/01/02 02:43:53 UTC

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

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

 ##########
 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)) {
 
 Review comment:
   > I would rather to match only when fetch and offset are null.
   
   When query and target have the same fetch and offset, it should be matched. you mean this rule should have same collations to keep the data semantics ? 

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