caicancai commented on code in PR #4845:
URL: https://github.com/apache/calcite/pull/4845#discussion_r2988504091


##########
core/src/main/java/org/apache/calcite/sql2rel/ConvertToChecked.java:
##########
@@ -72,6 +83,22 @@ class ConvertRexToChecked extends RexShuttle {
       List<RexNode> clonedOperands = visitList(call.operands, update);
       SqlKind kind = call.getKind();
       SqlOperator operator = call.getOperator();
+      SqlTypeName resultType = call.getType().getSqlTypeName();
+      boolean anyOperandIsInterval = false;
+      for (RexNode op : call.getOperands()) {
+        if 
(SqlTypeName.INTERVAL_TYPES.contains(op.getType().getSqlTypeName())) {
+          anyOperandIsInterval = true;
+          break;
+        }
+      }
+      boolean resultIsInterval = 
SqlTypeName.INTERVAL_TYPES.contains(resultType);
+      boolean rewrite =
+          // Do not rewrite operator if the type is e.g., DOUBLE or DATE
+          (this.allArithmetic && SqlTypeName.EXACT_TYPES.contains(resultType))
+          // But always rewrite if the type is an INTERVAL and any operand is 
INTERVAL
+          // This will not rewrite date subtraction, for example
+          || (resultIsInterval && anyOperandIsInterval);

Review Comment:
   Why is the condition anyOperandIsInterval needed?🤔



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