danny0405 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_r296636269
##########
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:
Instead of `equals`, we should compare the input's 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:
[email protected]
With regards,
Apache Git Services