jinxing64 commented on a change in pull request #1333: [CALCITE-3214] Add 
UnionToUnionRule for materialization matching.
URL: https://github.com/apache/calcite/pull/1333#discussion_r314568523
 
 

 ##########
 File path: 
core/src/main/java/org/apache/calcite/plan/MaterializedViewSubstitutionVisitor.java
 ##########
 @@ -180,6 +182,39 @@ public UnifyResult apply(UnifyRuleCall call) {
     }
   }
 
+  /**
+   * Implementation of {@link SubstitutionVisitor.UnifyRule} that matches a
+   * {@link MutableUnion} to a {@link MutableUnion} where the query and target
+   * have the same inputs but might not have the same order.
+   */
+  private static class UnionToUnionRule extends AbstractUnifyRule {
+    public static final UnionToUnionRule INSTANCE = new UnionToUnionRule();
+
+    private UnionToUnionRule() {
+      super(any(MutableUnion.class), any(MutableUnion.class), 0);
+    }
+
+    public UnifyResult apply(UnifyRuleCall call) {
+      final MutableUnion query = (MutableUnion) call.query;
+      final MutableUnion target = (MutableUnion) call.target;
+      List<MutableRel> queryInputs = query.getInputs();
+      List<MutableRel> targetInputs = target.getInputs();
+      if (queryInputs.size() == targetInputs.size()) {
+        while (!queryInputs.isEmpty()) {
 
 Review comment:
   hmm~ let me think. The process of removing elements might be 
useful/necessary.
   Let's make an example. Say Query and MV are like below:
   ```
   Query:
   Union
   +--ScanA
   +--ScanA
   +--ScanB
   
   MV:
   Union
   +--ScanA
   +--ScanB
   +--ScanB
   ```
   Obviously the matching should be failed, but if I implement like below:
   ```
   if (queryInputs.size() == targetInputs.size()) {
     for (MutableRel rel: queryInputs) {
       if (targetInputs.indexOf(queryInputs.get(0)) == -1) {
         return null;
       }
     }
   }
   return true;
   ```
   
   The matching will succeeded, which is not correct. Though all input scans of 
query exist in MV, the counts are different.
   
   THX again for review this :)

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


With regards,
Apache Git Services

Reply via email to