alex-plekhanov commented on code in PR #10541:
URL: https://github.com/apache/ignite/pull/10541#discussion_r1119756876


##########
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/util/IgniteMath.java:
##########
@@ -0,0 +1,172 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.query.calcite.util;
+
+import static org.apache.calcite.sql.type.SqlTypeName.BIGINT;
+import static org.apache.calcite.sql.type.SqlTypeName.INTEGER;
+import static org.apache.calcite.sql.type.SqlTypeName.SMALLINT;
+import static org.apache.calcite.sql.type.SqlTypeName.TINYINT;
+
+/** Math operations with overflow checking. */
+public class IgniteMath {
+
+    /** Returns the sum of its arguments, throwing an exception if the result 
overflows an {@code long}. */
+    public static long addExact(long x, long y) {
+        long r = x + y;
+
+        if (((x ^ r) & (y ^ r)) < 0) {
+            throw new ArithmeticException(BIGINT.getName() + " overflow");

Review Comment:
   Braces should not be used for one liners



##########
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/exp/IgniteExpressions.java:
##########
@@ -0,0 +1,133 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.query.calcite.exec.exp;
+
+import java.lang.reflect.Type;
+import org.apache.calcite.linq4j.tree.Expression;
+import org.apache.calcite.linq4j.tree.ExpressionType;
+import org.apache.calcite.linq4j.tree.Expressions;
+import org.apache.ignite.internal.processors.query.calcite.util.IgniteMath;
+
+/** Calcite liq4j expressions customized for Ignite*/
+public class IgniteExpressions {
+

Review Comment:
   Redundant NL (in other files too)



##########
modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/StdSqlOperatorsTest.java:
##########
@@ -348,6 +349,26 @@ public void testCurrentTimeFunctions() {
         assertExpression("LOCALTIMESTAMP").check();
     }
 
+    /** */
+    @Test
+    public void testArithmeticOverflow() {
+        assertThrows("select 9223372036854775807 + 1", 
IgniteSQLException.class, "BIGINT overflow");
+        assertThrows("select 9223372036854775807 * 2", 
IgniteSQLException.class, "BIGINT overflow");
+        assertThrows("select -9223372036854775808 - 1", 
IgniteSQLException.class, "BIGINT overflow");

Review Comment:
   Let's add also:
   ```
           assertThrows("select -(-9223372036854775808)", 
IgniteSQLException.class, "BIGINT overflow");
           assertThrows("select -9223372036854775808 / -1", 
IgniteSQLException.class, "BIGINT overflow");
   ```
   (fail now)



##########
modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/StdSqlOperatorsTest.java:
##########
@@ -348,6 +349,26 @@ public void testCurrentTimeFunctions() {
         assertExpression("LOCALTIMESTAMP").check();
     }
 
+    /** */
+    @Test
+    public void testArithmeticOverflow() {

Review Comment:
   This test class should only check basic operator usage (one test for each 
operator) and should not be overloaded with other checks. Let's move this test 
to another class. For example, `DataTypesTest`. 



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