mihaibudiu commented on code in PR #5360:
URL: https://github.com/apache/calcite/pull/5360#discussion_r4432391992


##########
core/src/main/java/org/apache/calcite/rel/rules/ReduceExpressionsRule.java:
##########
@@ -471,9 +471,44 @@ public CalcReduceExpressionsRule(Class<? extends Calc> 
calcClass,
       for (RexNode expr : exprList) {
         expandedExprList.add(expr.accept(shuttle));
       }
+
+      final List<RexNode> origProjectExprs = new ArrayList<>();
+      for (RexLocalRef projectExpr : program.getProjectList()) {
+        origProjectExprs.add(expandedExprList.get(projectExpr.getIndex()));
+      }
+      final @Nullable RexLocalRef origConditionRef = program.getCondition();
+      final @Nullable RexNode origConditionExpr =
+          origConditionRef != null
+              ? expandedExprList.get(origConditionRef.getIndex())
+              : null;
+
       final RelOptPredicateList predicates = RelOptPredicateList.EMPTY;
       if (reduceExpressions(calc, expandedExprList, predicates, false,
           config.matchNullability(), config.treatDynamicCallsAsConstant())) {
+
+        // Check whether the output expressions actually changed.
+        // reduceExpressions may return true because it simplified an
+        // intermediate expression, but the output (projects + condition)
+        // may still be equivalent to the original.
+        boolean outputChanged = false;
+        final List<RexLocalRef> projectList = program.getProjectList();
+        for (int i = 0; i < projectList.size(); i++) {

Review Comment:
   are the two sizes always equal?
   if yes, an assertion may be useful



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