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/06/24 12:26:13 UTC

[GitHub] [calcite] DonnyZone commented on a change in pull request #1274: [CALCITE-771] Use materialization for scan-project-sort query

DonnyZone commented on a change in pull request #1274: [CALCITE-771] Use materialization for scan-project-sort query
URL: https://github.com/apache/calcite/pull/1274#discussion_r296696099
 
 

 ##########
 File path: core/src/main/java/org/apache/calcite/plan/SubstitutionVisitor.java
 ##########
 @@ -1202,6 +1207,83 @@ public UnifyResult apply(UnifyRuleCall call) {
     }
   }
 
+  /** Implementation of {@link UnifyRule} that matches a
+   * {@link MutableSort} on {@link MutableProject} to a
+   * {@link MutableSort} on {@link MutableProject}.
+   *
+   * <p>Example: target has same collation as that of query</p>
+   * <ul>
+   * <li>query:   Sort(sort0=[$0], dir0=[ASC])
+   *                Project(projects: [$0, $1])
+   *                  Scan(table: [hr, emps])</li>
+   * <li>target:  Sort(sort0=[$0], dir0=[ASC])
+   *                Project(projects: [$0, $1, $2])
+   *                  Scan(table: [hr, emps])</li>
+   * </ul>*/
+  private static class SortOnProjectToSortOnProjectUnifyRule extends AbstractUnifyRule {
+    public static final SortOnProjectToSortOnProjectUnifyRule INSTANCE =
+        new SortOnProjectToSortOnProjectUnifyRule();
+
+    private SortOnProjectToSortOnProjectUnifyRule() {
+      super(
+          operand(MutableSort.class,
+              operand(MutableProject.class, query(0))),
+          operand(MutableSort.class,
+              operand(MutableProject.class, target(0))), 1);
+    }
+
+    protected UnifyResult apply(UnifyRuleCall call) {
+      final MutableSort query = (MutableSort) call.query;
+      final MutableSort target = (MutableSort) call.target;
+      final MutableProject queryProject = (MutableProject) query.getInput();
+      final MutableProject targetProject = (MutableProject) target.getInput();
+      if (!queryProject.getInput().equals(targetProject.getInput())) {
 
 Review comment:
   I checked all kinds of MutableRel nodes and found `equals` can cover the properties in `digest`.

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