xtern commented on code in PR #7400:
URL: https://github.com/apache/ignite-3/pull/7400#discussion_r2690222635


##########
modules/api/src/main/java/org/apache/ignite/table/TupleImpl.java:
##########
@@ -459,4 +483,89 @@ private <T> T valueNotNull(String columnName) {
 
         return value;
     }
+
+    private static byte castToByte(Number number) {
+        Class<? extends Number> cls = number.getClass();
+
+        if (cls == Long.class || cls == Integer.class || cls == Short.class) {
+            long longVal = number.longValue();
+            byte byteVal = number.byteValue();
+
+            if (longVal == byteVal) {
+                return byteVal;
+            }
+
+            throw new ArithmeticException("Byte value overflow");
+        }
+
+        return (byte) number;
+    }
+
+    private static short castToShort(Number number) {
+        Class<? extends Number> cls = number.getClass();
+
+        if (cls == Long.class || cls == Integer.class || cls == Byte.class) {
+            long longVal = number.longValue();
+            short shortVal = number.shortValue();
+
+            if (longVal == shortVal) {
+                return shortVal;
+            }
+
+            throw new ArithmeticException("Short value overflow");
+        }
+
+        return (short) number;
+    }
+
+    private static int castToInt(Number number) {

Review Comment:
   This won't work because Number can be float/double/decimal also and we must 
validate that the conversion is valid.



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