cloud-fan commented on a change in pull request #26995: [SPARK-30341][SQL] Overflow check for interval arithmetic operations URL: https://github.com/apache/spark/pull/26995#discussion_r372905544
########## File path: sql/core/src/test/resources/sql-tests/results/interval.sql.out ########## @@ -1101,3 +1102,45 @@ select interval '1 ' day struct<INTERVAL '1 days':interval> -- !query 113 output 1 days + + +-- !query 114 +select -(a) from values (interval '-2147483648 months', interval '2147483647 months') t(a, b) +-- !query 114 schema +struct<(- a):interval> +-- !query 114 output +-178956970 years -8 months + + +-- !query 115 +select a - b from values (interval '-2147483648 months', interval '2147483647 months') t(a, b) +-- !query 115 schema +struct<(a - b):interval> +-- !query 115 output +1 months + + +-- !query 116 +select b + interval '1 month' from values (interval '-2147483648 months', interval '2147483647 months') t(a, b) +-- !query 116 schema +struct<(b + INTERVAL '1 months'):interval> +-- !query 116 output +-178956970 years -8 months + + +-- !query 117 +select a * 1.1 from values (interval '-2147483648 months', interval '2147483647 months') t(a, b) +-- !query 117 schema +struct<> +-- !query 117 output +java.lang.ArithmeticException +integer overflow Review comment: IIRC a problem is: the new operators in 3.0 (`interval * double` and `interval / double`) do not have a reasonable java style overflow behavior. The actual operation is `(int * double).toInt`, and `Double.PositiveInfinity.toInt` returns `Int.Max`, which can be confusing. Since ansi mode is off by default, we are introducing a new behavior that is non-ansi, which is weird. There are 2 options: 1. `interval * double` and `interval / double` return max or min int/long value when overflow. `interval / 0` returns null. 2. revert these 2 operators. @gatorsmile what do you think? ---------------------------------------------------------------- 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: [email protected] With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
