jduo commented on code in PR #3616:
URL: https://github.com/apache/calcite/pull/3616#discussion_r1529075316


##########
core/src/main/java/org/apache/calcite/plan/SubstitutionVisitor.java:
##########
@@ -649,6 +661,96 @@ assert rowTypesAreEquivalent(
     return substitutions;
   }
 
+  /**
+   * Find out the replacements belongs to the real substitution and undo the 
rest.
+   * The rest replacements are exploratory, they are no more needed when this 
attempt finished.
+   */
+  private List<Replacement> undoAndRemoveExploratoryReplacements(
+      List<Replacement> attempted, List<MutableRel> targetDescendants,
+      MutableRel replacement, boolean lastIsFinalReplacement) {
+    final List<Replacement> realReplacements = new ArrayList<>();
+    final List<Replacement> exploratoryReplacements =
+        new ArrayList<>(lastIsFinalReplacement
+            ? attempted.subList(0, attempted.size() - 1)
+            : attempted);
+    findOutRealReplacements(
+        exploratoryReplacements,
+        realReplacements,
+        null,
+        targetDescendants,
+        replacement);
+    Collections.reverse(realReplacements);
+    exploratoryReplacements.removeAll(realReplacements);
+    undoReplacement(exploratoryReplacements);
+    if (lastIsFinalReplacement) {
+      realReplacements.add(attempted.get(attempted.size() - 1));
+    }
+    return realReplacements;
+  }
+
+  private void findOutRealReplacements(

Review Comment:
   Rename findOutRealReplacements -> findRealReplacements() (or maybe 
identifyRealReplacements())



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

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to