caicancai commented on code in PR #4845:
URL: https://github.com/apache/calcite/pull/4845#discussion_r2985330254
##########
core/src/test/resources/sql/scalar.iq:
##########
@@ -18,6 +18,32 @@
!set outputformat mysql
!use scott
+# 5 test cases for [CALCITE-7443] Incorrect simplification for large interval
+SELECT -(INTERVAL -2147483648 months);
+java.lang.ArithmeticException: integer overflow
+
+!error
+
+SELECT INTERVAL 2147483647 years;
+java.lang.ArithmeticException: integer overflow
+
+!error
+
+SELECT -(INTERVAL -9223372036854775.808 SECONDS);
+java.lang.ArithmeticException: long overflow
+
+!error
+
+SELECT INTERVAL 3000000 months * 1000;
+java.lang.ArithmeticException: integer overflow
+
+!error
+
+SELECT INTERVAL 3000000 months / .0001;
+java.lang.ArithmeticException: Overflow
Review Comment:
I'm not sure if this outputs a more complete error message; I'll take a look
at the code later.
##########
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
Review Comment:
I'm not sure if the comments are finished, because there's no further
content after "for example".
--
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]