mihaibudiu commented on code in PR #4044: URL: https://github.com/apache/calcite/pull/4044#discussion_r1845150215
########## core/src/test/resources/sql/cast.iq: ########## @@ -15,9 +15,54 @@ # See the License for the specific language governing permissions and # limitations under the License. # -!use scott + +# This connection uses checked arithmetic +!use scott-checked-rounding-half-up !set outputformat mysql +# Test cases for [CALCITE-6685] There is no support for checked arithmetic +# https://issues.apache.org/jira/browse/CALCITE-6685 + +select 2 * CAST(5e18 AS DECIMAL(19, 0)); +java.lang.ArithmeticException: Value 10000000000000000000 cannot be represented as a DECIMAL(19, 0) +!error + +select - CAST(-2147483648 AS INT); +Caused by: java.lang.ArithmeticException +!error + +select CAST(1 AS SMALLINT) + CAST(2 AS SMALLINT) AS C; ++---+ +| C | ++---+ +| 3 | ++---+ +(1 row) + +!ok + +select CAST(127 AS TINYINT) + CAST(2 AS TINYINT) AS C; +Caused by: java.lang.ArithmeticException: integer overflow: Value 129 does not fit in a TINYINT +!error + +select -2147483648 - 1; +Caused by: java.lang.ArithmeticException +!error + +select -2147483648 / -1; Review Comment: there is no checked arithmetic for FP. there is no overflow in FP, that's why there is an Infinity. ########## testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java: ########## @@ -3419,8 +3423,10 @@ static void checkOverlaps(OverlapChecker c) { } @Test void testMultiplyOperator() { - final SqlOperatorFixture f = fixture(); - f.setFor(SqlStdOperatorTable.MULTIPLY, VmName.EXPAND); + final SqlOperatorFixture f = fixture() + .setFor(SqlStdOperatorTable.MULTIPLY, VmName.EXPAND) + // BigQuery requires arithmetic overflows Review Comment: Any of the dialects that uses checked arithmetic would work. They all behave in the same way. ########## core/src/main/java/org/apache/calcite/sql/fun/SqlStdOperatorTable.java: ########## @@ -294,6 +294,19 @@ public class SqlStdOperatorTable extends ReflectiveSqlOperatorTable { InferTypes.FIRST_KNOWN, OperandTypes.DIVISION_OPERATOR); + /** + * Checked version of arithmetic division operator, '<code>/</code>'. + */ + public static final SqlBinaryOperator CHECKED_DIVIDE = Review Comment: this is integer division -- 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]
