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


##########
modules/api/src/testFixtures/java/org/apache/ignite/table/AbstractImmutableTupleTest.java:
##########
@@ -334,6 +340,375 @@ public void nullPointerWhenReadingNullByNameAsPrimitive(
         assertEquals(String.format(NULL_TO_PRIMITIVE_NAMED_ERROR_MESSAGE, 
"VAL"), err.getMessage());
     }
 
+    @Test
+    void testReadAsByte() {
+        Tuple tuple = createTupleOfSingleColumn(ColumnType.INT8, "INT8", 
Byte.MAX_VALUE);
+
+        assertThat(tuple.byteValue("INT8"), is(Byte.MAX_VALUE));
+        assertThat(tuple.shortValue("INT8"), is((short) Byte.MAX_VALUE));
+        assertThat(tuple.intValue("INT8"), is((int) Byte.MAX_VALUE));
+        assertThat(tuple.longValue("INT8"), is((long) Byte.MAX_VALUE));
+
+        assertThat(tuple.byteValue(0), is(Byte.MAX_VALUE));
+        assertThat(tuple.shortValue(0), is((short) Byte.MAX_VALUE));
+        assertThat(tuple.intValue(0), is((int) Byte.MAX_VALUE));
+        assertThat(tuple.longValue(0), is((long) Byte.MAX_VALUE));
+    }
+
+    @Test
+    void testReadAsShort() {
+        // The field value is within the byte range
+        {
+            String columnName = "INT16";
+            short value = Byte.MAX_VALUE;
+            Tuple tuple = createTupleOfSingleColumn(ColumnType.INT16, 
columnName, value);
+
+            assertThat(tuple.byteValue(columnName), is((byte) value));
+            assertThat(tuple.shortValue(columnName), is(value));
+            assertThat(tuple.intValue(columnName), is((int) value));
+            assertThat(tuple.longValue(columnName), is((long) value));
+
+            assertThat(tuple.byteValue(0), is((byte) value));
+            assertThat(tuple.shortValue(0), is(value));
+            assertThat(tuple.intValue(0), is((int) value));
+            assertThat(tuple.longValue(0), is((long) value));
+        }
+
+        // The field value is out of the byte range.
+        {
+            String columnName = "INT16";
+            short value = Byte.MAX_VALUE + 1;
+            Tuple tuple = createTupleOfSingleColumn(ColumnType.INT16, 
columnName, value);
+
+            ArithmeticException ex0 = assertThrows(ArithmeticException.class, 
() -> tuple.byteValue(columnName));
+            assertThat(ex0.getMessage(), equalTo("Byte value overflow"));
+
+            assertThat(tuple.shortValue(columnName), is(value));
+            assertThat(tuple.intValue(columnName), is((int) value));
+            assertThat(tuple.longValue(columnName), is((long) value));
+
+            ArithmeticException ex1 = assertThrows(ArithmeticException.class, 
() -> tuple.byteValue(0));
+            assertThat(ex1.getMessage(), equalTo("Byte value overflow"));
+
+            assertThat(tuple.shortValue(0), is(value));
+            assertThat(tuple.intValue(0), is((int) value));
+            assertThat(tuple.longValue(0), is((long) value));
+        }
+    }
+
+    @Test
+    void testReadAsInt() {
+        {
+            int value = Byte.MAX_VALUE;
+            String columnName = "VALUE";
+            Tuple tuple = createTupleOfSingleColumn(ColumnType.INT32, 
columnName, value);
+
+            assertThat(tuple.byteValue(columnName), is((byte) value));
+            assertThat(tuple.shortValue(columnName), is((short) value));
+            assertThat(tuple.intValue(columnName), is(value));
+            assertThat(tuple.longValue(columnName), is((long) value));
+
+            assertThat(tuple.byteValue(0), is((byte) value));
+            assertThat(tuple.shortValue(0), is((short) value));
+            assertThat(tuple.intValue(0), is(value));
+            assertThat(tuple.longValue(0), is((long) value));
+        }
+
+        {
+            int value = Byte.MAX_VALUE + 1;
+            String columnName = "VALUE";
+            Tuple tuple = createTupleOfSingleColumn(ColumnType.INT32, 
columnName, value);
+
+            ArithmeticException ex0 = assertThrows(ArithmeticException.class, 
() -> tuple.byteValue(columnName));
+            assertThat(ex0.getMessage(), equalTo("Byte value overflow"));
+
+            assertThat(tuple.shortValue(columnName), is((short) value));
+            assertThat(tuple.intValue(columnName), is(value));
+            assertThat(tuple.longValue(columnName), is((long) value));
+
+            ArithmeticException ex1 = assertThrows(ArithmeticException.class, 
() -> tuple.byteValue(0));
+            assertThat(ex1.getMessage(), equalTo("Byte value overflow"));
+
+            assertThat(tuple.shortValue(0), is((short) value));
+            assertThat(tuple.intValue(0), is(value));
+            assertThat(tuple.longValue(0), is((long) value));
+        }
+
+        {
+            int value = Short.MAX_VALUE + 1;
+            String columnName = "VALUE";
+            Tuple tuple = createTupleOfSingleColumn(ColumnType.INT32, 
columnName, value);
+
+            {
+                ArithmeticException ex = 
assertThrows(ArithmeticException.class, () -> tuple.byteValue(columnName));
+                assertThat(ex.getMessage(), equalTo("Byte value overflow"));
+            }
+
+            {
+                ArithmeticException ex = 
assertThrows(ArithmeticException.class, () -> tuple.shortValue(columnName));
+                assertThat(ex.getMessage(), equalTo("Short value overflow"));
+            }
+
+            assertThat(tuple.intValue(columnName), is(value));
+            assertThat(tuple.longValue(columnName), is((long) value));
+
+            {
+                ArithmeticException ex = 
assertThrows(ArithmeticException.class, () -> tuple.byteValue(0));
+                assertThat(ex.getMessage(), equalTo("Byte value overflow"));
+            }
+
+            {
+                ArithmeticException ex = 
assertThrows(ArithmeticException.class, () -> tuple.shortValue(0));
+                assertThat(ex.getMessage(), equalTo("Short value overflow"));
+            }
+
+            assertThat(tuple.intValue(0), is(value));
+            assertThat(tuple.longValue(0), is((long) value));
+        }
+    }
+
+    @Test
+    void testReadAsLong() {
+        {
+            long value = Byte.MAX_VALUE;
+            String columnName = "VALUE";
+            Tuple tuple = createTupleOfSingleColumn(ColumnType.INT64, 
columnName, value);
+
+            assertThat(tuple.byteValue(columnName), is((byte) value));
+            assertThat(tuple.shortValue(columnName), is((short) value));
+            assertThat(tuple.intValue(columnName), is((int) value));
+            assertThat(tuple.longValue(columnName), is(value));
+
+            assertThat(tuple.byteValue(0), is((byte) value));
+            assertThat(tuple.shortValue(0), is((short) value));
+            assertThat(tuple.intValue(0), is((int) value));
+            assertThat(tuple.longValue(0), is(value));
+        }
+
+        {
+            long value = Byte.MAX_VALUE + 1;
+            String columnName = "VALUE";
+            Tuple tuple = createTupleOfSingleColumn(ColumnType.INT64, 
columnName, value);
+
+            ArithmeticException ex0 = assertThrows(ArithmeticException.class, 
() -> tuple.byteValue(columnName));
+            assertThat(ex0.getMessage(), equalTo("Byte value overflow"));
+
+            assertThat(tuple.shortValue(columnName), is((short) value));
+            assertThat(tuple.intValue(columnName), is((int) value));
+            assertThat(tuple.longValue(columnName), is(value));
+
+            ArithmeticException ex1 = assertThrows(ArithmeticException.class, 
() -> tuple.byteValue(0));
+            assertThat(ex1.getMessage(), equalTo("Byte value overflow"));
+
+            assertThat(tuple.shortValue(0), is((short) value));
+            assertThat(tuple.intValue(0), is((int) value));
+            assertThat(tuple.longValue(0), is(value));
+        }
+
+        {
+            long value = Short.MAX_VALUE + 1;
+            String columnName = "VALUE";
+            Tuple tuple = createTupleOfSingleColumn(ColumnType.INT64, 
columnName, value);
+
+            {
+                ArithmeticException ex = 
assertThrows(ArithmeticException.class, () -> tuple.byteValue(columnName));
+                assertThat(ex.getMessage(), equalTo("Byte value overflow"));
+            }
+
+            {
+                ArithmeticException ex = 
assertThrows(ArithmeticException.class, () -> tuple.shortValue(columnName));
+                assertThat(ex.getMessage(), equalTo("Short value overflow"));
+            }
+
+            assertThat(tuple.intValue(columnName), is((int) value));
+            assertThat(tuple.longValue(columnName), is(value));
+
+            {
+                ArithmeticException ex = 
assertThrows(ArithmeticException.class, () -> tuple.byteValue(0));
+                assertThat(ex.getMessage(), equalTo("Byte value overflow"));
+            }
+
+            {
+                ArithmeticException ex = 
assertThrows(ArithmeticException.class, () -> tuple.shortValue(0));
+                assertThat(ex.getMessage(), equalTo("Short value overflow"));
+            }
+
+            assertThat(tuple.intValue(0), is((int) value));
+            assertThat(tuple.longValue(0), is(value));
+        }
+
+        {
+            long value = Integer.MAX_VALUE + 1L;
+            String columnName = "VALUE";
+            Tuple tuple = createTupleOfSingleColumn(ColumnType.INT64, 
columnName, value);
+
+            {
+                ArithmeticException ex = 
assertThrows(ArithmeticException.class, () -> tuple.byteValue(columnName));
+                assertThat(ex.getMessage(), equalTo("Byte value overflow"));
+            }
+
+            {
+                ArithmeticException ex = 
assertThrows(ArithmeticException.class, () -> tuple.shortValue(columnName));
+                assertThat(ex.getMessage(), equalTo("Short value overflow"));
+            }
+
+            {
+                ArithmeticException ex = 
assertThrows(ArithmeticException.class, () -> tuple.intValue(columnName));
+                assertThat(ex.getMessage(), equalTo("Int value overflow"));
+            }
+
+            assertThat(tuple.longValue(columnName), is(value));
+
+            {
+                ArithmeticException ex = 
assertThrows(ArithmeticException.class, () -> tuple.byteValue(0));
+                assertThat(ex.getMessage(), equalTo("Byte value overflow"));
+            }
+
+            {
+                ArithmeticException ex = 
assertThrows(ArithmeticException.class, () -> tuple.shortValue(0));
+                assertThat(ex.getMessage(), equalTo("Short value overflow"));
+            }
+
+            {
+                ArithmeticException ex = 
assertThrows(ArithmeticException.class, () -> tuple.intValue(0));
+                assertThat(ex.getMessage(), equalTo("Int value overflow"));
+            }
+
+            assertThat(tuple.longValue(0), is(value));
+        }
+    }
+
+    @Test
+    void testReadAsFloat() {
+        {
+            Tuple tuple = createTupleOfSingleColumn(ColumnType.FLOAT, "FLOAT", 
Float.MAX_VALUE);
+
+            assertThat(tuple.floatValue("FLOAT"), is(Float.MAX_VALUE));
+            assertThat(tuple.doubleValue("FLOAT"), is((double) 
Float.MAX_VALUE));
+
+            assertThat(tuple.floatValue(0), is(Float.MAX_VALUE));
+            assertThat(tuple.doubleValue(0), is((double) Float.MAX_VALUE));
+        }
+
+        // NaN
+        {
+            Tuple tuple = createTupleOfSingleColumn(ColumnType.FLOAT, "FLOAT", 
Float.NaN);
+
+            assertThat(Float.isNaN(tuple.floatValue("FLOAT")), is(true));
+            assertThat(Double.isNaN(tuple.doubleValue("FLOAT")), is(true));
+
+            assertThat(Float.isNaN(tuple.floatValue(0)), is(true));
+            assertThat(Double.isNaN(tuple.doubleValue(0)), is(true));
+        }
+
+        // Positive infinity
+        {
+            Tuple tuple = createTupleOfSingleColumn(ColumnType.FLOAT, "FLOAT", 
Float.POSITIVE_INFINITY);
+
+            assertThat(tuple.floatValue("FLOAT"), is(Float.POSITIVE_INFINITY));
+            assertThat(tuple.doubleValue("FLOAT"), 
is(Double.POSITIVE_INFINITY));
+
+            assertThat(tuple.floatValue(0), is(Float.POSITIVE_INFINITY));
+            assertThat(tuple.doubleValue(0), is(Double.POSITIVE_INFINITY));
+        }
+
+        // Negative infinity
+        {
+            Tuple tuple = createTupleOfSingleColumn(ColumnType.FLOAT, "FLOAT", 
Float.NEGATIVE_INFINITY);
+
+            assertThat(tuple.floatValue("FLOAT"), is(Float.NEGATIVE_INFINITY));
+            assertThat(tuple.doubleValue("FLOAT"), 
is(Double.NEGATIVE_INFINITY));
+
+            assertThat(tuple.floatValue(0), is(Float.NEGATIVE_INFINITY));
+            assertThat(tuple.doubleValue(0), is(Double.NEGATIVE_INFINITY));
+        }
+    }
+
+    @Test
+    void testReadAsDouble() {
+        String columnName = "DOUBLE";
+
+        // The field value can be represented as float.
+        {
+            double value = Float.MAX_VALUE;
+            Tuple tuple = createTupleOfSingleColumn(ColumnType.DOUBLE, 
columnName, value);
+
+            assertThat(tuple.floatValue(columnName), is((float) value));
+            assertThat(tuple.floatValue(0), is((float) value));
+
+            assertThat(tuple.doubleValue(columnName), is(value));
+            assertThat(tuple.doubleValue(0), is(value));
+        }
+
+        // The field value cannot be represented as float.
+        {
+            double value = Double.MAX_VALUE;
+            Tuple tuple = createTupleOfSingleColumn(ColumnType.DOUBLE, 
columnName, value);
+
+            ArithmeticException ex0 = assertThrows(ArithmeticException.class, 
() -> tuple.floatValue(columnName));
+            assertThat(ex0.getMessage(), equalTo("Float value overflow"));
+
+            ArithmeticException ex1 = assertThrows(ArithmeticException.class, 
() -> tuple.floatValue(0));
+            assertThat(ex1.getMessage(), equalTo("Float value overflow"));
+
+            assertThat(tuple.doubleValue(columnName), is(value));
+            assertThat(tuple.doubleValue(0), is(value));
+        }
+
+        // NaN
+        {
+            Tuple tuple = createTupleOfSingleColumn(ColumnType.DOUBLE, 
columnName, Double.NaN);
+
+            assertThat(Float.isNaN(tuple.floatValue(columnName)), is(true));
+            assertThat(Double.isNaN(tuple.doubleValue(columnName)), is(true));
+
+            assertThat(Float.isNaN(tuple.floatValue(0)), is(true));
+            assertThat(Double.isNaN(tuple.doubleValue(0)), is(true));
+        }
+
+        // Positive infinity
+        {
+            Tuple tuple = createTupleOfSingleColumn(ColumnType.FLOAT, 
columnName, Double.POSITIVE_INFINITY);

Review Comment:
   Fixed



##########
modules/api/src/testFixtures/java/org/apache/ignite/table/AbstractImmutableTupleTest.java:
##########
@@ -334,6 +340,375 @@ public void nullPointerWhenReadingNullByNameAsPrimitive(
         assertEquals(String.format(NULL_TO_PRIMITIVE_NAMED_ERROR_MESSAGE, 
"VAL"), err.getMessage());
     }
 
+    @Test
+    void testReadAsByte() {
+        Tuple tuple = createTupleOfSingleColumn(ColumnType.INT8, "INT8", 
Byte.MAX_VALUE);
+
+        assertThat(tuple.byteValue("INT8"), is(Byte.MAX_VALUE));
+        assertThat(tuple.shortValue("INT8"), is((short) Byte.MAX_VALUE));
+        assertThat(tuple.intValue("INT8"), is((int) Byte.MAX_VALUE));
+        assertThat(tuple.longValue("INT8"), is((long) Byte.MAX_VALUE));
+
+        assertThat(tuple.byteValue(0), is(Byte.MAX_VALUE));
+        assertThat(tuple.shortValue(0), is((short) Byte.MAX_VALUE));
+        assertThat(tuple.intValue(0), is((int) Byte.MAX_VALUE));
+        assertThat(tuple.longValue(0), is((long) Byte.MAX_VALUE));
+    }
+
+    @Test
+    void testReadAsShort() {
+        // The field value is within the byte range
+        {
+            String columnName = "INT16";
+            short value = Byte.MAX_VALUE;
+            Tuple tuple = createTupleOfSingleColumn(ColumnType.INT16, 
columnName, value);
+
+            assertThat(tuple.byteValue(columnName), is((byte) value));
+            assertThat(tuple.shortValue(columnName), is(value));
+            assertThat(tuple.intValue(columnName), is((int) value));
+            assertThat(tuple.longValue(columnName), is((long) value));
+
+            assertThat(tuple.byteValue(0), is((byte) value));
+            assertThat(tuple.shortValue(0), is(value));
+            assertThat(tuple.intValue(0), is((int) value));
+            assertThat(tuple.longValue(0), is((long) value));
+        }
+
+        // The field value is out of the byte range.
+        {
+            String columnName = "INT16";
+            short value = Byte.MAX_VALUE + 1;
+            Tuple tuple = createTupleOfSingleColumn(ColumnType.INT16, 
columnName, value);
+
+            ArithmeticException ex0 = assertThrows(ArithmeticException.class, 
() -> tuple.byteValue(columnName));
+            assertThat(ex0.getMessage(), equalTo("Byte value overflow"));
+
+            assertThat(tuple.shortValue(columnName), is(value));
+            assertThat(tuple.intValue(columnName), is((int) value));
+            assertThat(tuple.longValue(columnName), is((long) value));
+
+            ArithmeticException ex1 = assertThrows(ArithmeticException.class, 
() -> tuple.byteValue(0));
+            assertThat(ex1.getMessage(), equalTo("Byte value overflow"));
+
+            assertThat(tuple.shortValue(0), is(value));
+            assertThat(tuple.intValue(0), is((int) value));
+            assertThat(tuple.longValue(0), is((long) value));
+        }
+    }
+
+    @Test
+    void testReadAsInt() {
+        {
+            int value = Byte.MAX_VALUE;
+            String columnName = "VALUE";
+            Tuple tuple = createTupleOfSingleColumn(ColumnType.INT32, 
columnName, value);
+
+            assertThat(tuple.byteValue(columnName), is((byte) value));
+            assertThat(tuple.shortValue(columnName), is((short) value));
+            assertThat(tuple.intValue(columnName), is(value));
+            assertThat(tuple.longValue(columnName), is((long) value));
+
+            assertThat(tuple.byteValue(0), is((byte) value));
+            assertThat(tuple.shortValue(0), is((short) value));
+            assertThat(tuple.intValue(0), is(value));
+            assertThat(tuple.longValue(0), is((long) value));
+        }
+
+        {
+            int value = Byte.MAX_VALUE + 1;
+            String columnName = "VALUE";
+            Tuple tuple = createTupleOfSingleColumn(ColumnType.INT32, 
columnName, value);
+
+            ArithmeticException ex0 = assertThrows(ArithmeticException.class, 
() -> tuple.byteValue(columnName));
+            assertThat(ex0.getMessage(), equalTo("Byte value overflow"));
+
+            assertThat(tuple.shortValue(columnName), is((short) value));
+            assertThat(tuple.intValue(columnName), is(value));
+            assertThat(tuple.longValue(columnName), is((long) value));
+
+            ArithmeticException ex1 = assertThrows(ArithmeticException.class, 
() -> tuple.byteValue(0));
+            assertThat(ex1.getMessage(), equalTo("Byte value overflow"));
+
+            assertThat(tuple.shortValue(0), is((short) value));
+            assertThat(tuple.intValue(0), is(value));
+            assertThat(tuple.longValue(0), is((long) value));
+        }
+
+        {
+            int value = Short.MAX_VALUE + 1;
+            String columnName = "VALUE";
+            Tuple tuple = createTupleOfSingleColumn(ColumnType.INT32, 
columnName, value);
+
+            {
+                ArithmeticException ex = 
assertThrows(ArithmeticException.class, () -> tuple.byteValue(columnName));
+                assertThat(ex.getMessage(), equalTo("Byte value overflow"));
+            }
+
+            {
+                ArithmeticException ex = 
assertThrows(ArithmeticException.class, () -> tuple.shortValue(columnName));
+                assertThat(ex.getMessage(), equalTo("Short value overflow"));
+            }
+
+            assertThat(tuple.intValue(columnName), is(value));
+            assertThat(tuple.longValue(columnName), is((long) value));
+
+            {
+                ArithmeticException ex = 
assertThrows(ArithmeticException.class, () -> tuple.byteValue(0));
+                assertThat(ex.getMessage(), equalTo("Byte value overflow"));
+            }
+
+            {
+                ArithmeticException ex = 
assertThrows(ArithmeticException.class, () -> tuple.shortValue(0));
+                assertThat(ex.getMessage(), equalTo("Short value overflow"));
+            }
+
+            assertThat(tuple.intValue(0), is(value));
+            assertThat(tuple.longValue(0), is((long) value));
+        }
+    }
+
+    @Test
+    void testReadAsLong() {
+        {
+            long value = Byte.MAX_VALUE;
+            String columnName = "VALUE";
+            Tuple tuple = createTupleOfSingleColumn(ColumnType.INT64, 
columnName, value);
+
+            assertThat(tuple.byteValue(columnName), is((byte) value));
+            assertThat(tuple.shortValue(columnName), is((short) value));
+            assertThat(tuple.intValue(columnName), is((int) value));
+            assertThat(tuple.longValue(columnName), is(value));
+
+            assertThat(tuple.byteValue(0), is((byte) value));
+            assertThat(tuple.shortValue(0), is((short) value));
+            assertThat(tuple.intValue(0), is((int) value));
+            assertThat(tuple.longValue(0), is(value));
+        }
+
+        {
+            long value = Byte.MAX_VALUE + 1;
+            String columnName = "VALUE";
+            Tuple tuple = createTupleOfSingleColumn(ColumnType.INT64, 
columnName, value);
+
+            ArithmeticException ex0 = assertThrows(ArithmeticException.class, 
() -> tuple.byteValue(columnName));
+            assertThat(ex0.getMessage(), equalTo("Byte value overflow"));
+
+            assertThat(tuple.shortValue(columnName), is((short) value));
+            assertThat(tuple.intValue(columnName), is((int) value));
+            assertThat(tuple.longValue(columnName), is(value));
+
+            ArithmeticException ex1 = assertThrows(ArithmeticException.class, 
() -> tuple.byteValue(0));
+            assertThat(ex1.getMessage(), equalTo("Byte value overflow"));
+
+            assertThat(tuple.shortValue(0), is((short) value));
+            assertThat(tuple.intValue(0), is((int) value));
+            assertThat(tuple.longValue(0), is(value));
+        }
+
+        {
+            long value = Short.MAX_VALUE + 1;
+            String columnName = "VALUE";
+            Tuple tuple = createTupleOfSingleColumn(ColumnType.INT64, 
columnName, value);
+
+            {
+                ArithmeticException ex = 
assertThrows(ArithmeticException.class, () -> tuple.byteValue(columnName));
+                assertThat(ex.getMessage(), equalTo("Byte value overflow"));
+            }
+
+            {
+                ArithmeticException ex = 
assertThrows(ArithmeticException.class, () -> tuple.shortValue(columnName));
+                assertThat(ex.getMessage(), equalTo("Short value overflow"));
+            }
+
+            assertThat(tuple.intValue(columnName), is((int) value));
+            assertThat(tuple.longValue(columnName), is(value));
+
+            {
+                ArithmeticException ex = 
assertThrows(ArithmeticException.class, () -> tuple.byteValue(0));
+                assertThat(ex.getMessage(), equalTo("Byte value overflow"));
+            }
+
+            {
+                ArithmeticException ex = 
assertThrows(ArithmeticException.class, () -> tuple.shortValue(0));
+                assertThat(ex.getMessage(), equalTo("Short value overflow"));
+            }
+
+            assertThat(tuple.intValue(0), is((int) value));
+            assertThat(tuple.longValue(0), is(value));
+        }
+
+        {
+            long value = Integer.MAX_VALUE + 1L;
+            String columnName = "VALUE";
+            Tuple tuple = createTupleOfSingleColumn(ColumnType.INT64, 
columnName, value);
+
+            {
+                ArithmeticException ex = 
assertThrows(ArithmeticException.class, () -> tuple.byteValue(columnName));
+                assertThat(ex.getMessage(), equalTo("Byte value overflow"));
+            }
+
+            {
+                ArithmeticException ex = 
assertThrows(ArithmeticException.class, () -> tuple.shortValue(columnName));
+                assertThat(ex.getMessage(), equalTo("Short value overflow"));
+            }
+
+            {
+                ArithmeticException ex = 
assertThrows(ArithmeticException.class, () -> tuple.intValue(columnName));
+                assertThat(ex.getMessage(), equalTo("Int value overflow"));
+            }
+
+            assertThat(tuple.longValue(columnName), is(value));
+
+            {
+                ArithmeticException ex = 
assertThrows(ArithmeticException.class, () -> tuple.byteValue(0));
+                assertThat(ex.getMessage(), equalTo("Byte value overflow"));
+            }
+
+            {
+                ArithmeticException ex = 
assertThrows(ArithmeticException.class, () -> tuple.shortValue(0));
+                assertThat(ex.getMessage(), equalTo("Short value overflow"));
+            }
+
+            {
+                ArithmeticException ex = 
assertThrows(ArithmeticException.class, () -> tuple.intValue(0));
+                assertThat(ex.getMessage(), equalTo("Int value overflow"));
+            }
+
+            assertThat(tuple.longValue(0), is(value));
+        }
+    }
+
+    @Test
+    void testReadAsFloat() {
+        {
+            Tuple tuple = createTupleOfSingleColumn(ColumnType.FLOAT, "FLOAT", 
Float.MAX_VALUE);
+
+            assertThat(tuple.floatValue("FLOAT"), is(Float.MAX_VALUE));
+            assertThat(tuple.doubleValue("FLOAT"), is((double) 
Float.MAX_VALUE));
+
+            assertThat(tuple.floatValue(0), is(Float.MAX_VALUE));
+            assertThat(tuple.doubleValue(0), is((double) Float.MAX_VALUE));
+        }
+
+        // NaN
+        {
+            Tuple tuple = createTupleOfSingleColumn(ColumnType.FLOAT, "FLOAT", 
Float.NaN);
+
+            assertThat(Float.isNaN(tuple.floatValue("FLOAT")), is(true));
+            assertThat(Double.isNaN(tuple.doubleValue("FLOAT")), is(true));
+
+            assertThat(Float.isNaN(tuple.floatValue(0)), is(true));
+            assertThat(Double.isNaN(tuple.doubleValue(0)), is(true));
+        }
+
+        // Positive infinity
+        {
+            Tuple tuple = createTupleOfSingleColumn(ColumnType.FLOAT, "FLOAT", 
Float.POSITIVE_INFINITY);
+
+            assertThat(tuple.floatValue("FLOAT"), is(Float.POSITIVE_INFINITY));
+            assertThat(tuple.doubleValue("FLOAT"), 
is(Double.POSITIVE_INFINITY));
+
+            assertThat(tuple.floatValue(0), is(Float.POSITIVE_INFINITY));
+            assertThat(tuple.doubleValue(0), is(Double.POSITIVE_INFINITY));
+        }
+
+        // Negative infinity
+        {
+            Tuple tuple = createTupleOfSingleColumn(ColumnType.FLOAT, "FLOAT", 
Float.NEGATIVE_INFINITY);
+
+            assertThat(tuple.floatValue("FLOAT"), is(Float.NEGATIVE_INFINITY));
+            assertThat(tuple.doubleValue("FLOAT"), 
is(Double.NEGATIVE_INFINITY));
+
+            assertThat(tuple.floatValue(0), is(Float.NEGATIVE_INFINITY));
+            assertThat(tuple.doubleValue(0), is(Double.NEGATIVE_INFINITY));
+        }
+    }
+
+    @Test
+    void testReadAsDouble() {
+        String columnName = "DOUBLE";
+
+        // The field value can be represented as float.
+        {
+            double value = Float.MAX_VALUE;
+            Tuple tuple = createTupleOfSingleColumn(ColumnType.DOUBLE, 
columnName, value);
+
+            assertThat(tuple.floatValue(columnName), is((float) value));
+            assertThat(tuple.floatValue(0), is((float) value));
+
+            assertThat(tuple.doubleValue(columnName), is(value));
+            assertThat(tuple.doubleValue(0), is(value));
+        }
+
+        // The field value cannot be represented as float.
+        {
+            double value = Double.MAX_VALUE;
+            Tuple tuple = createTupleOfSingleColumn(ColumnType.DOUBLE, 
columnName, value);
+
+            ArithmeticException ex0 = assertThrows(ArithmeticException.class, 
() -> tuple.floatValue(columnName));
+            assertThat(ex0.getMessage(), equalTo("Float value overflow"));
+
+            ArithmeticException ex1 = assertThrows(ArithmeticException.class, 
() -> tuple.floatValue(0));
+            assertThat(ex1.getMessage(), equalTo("Float value overflow"));
+
+            assertThat(tuple.doubleValue(columnName), is(value));
+            assertThat(tuple.doubleValue(0), is(value));
+        }
+
+        // NaN
+        {
+            Tuple tuple = createTupleOfSingleColumn(ColumnType.DOUBLE, 
columnName, Double.NaN);
+
+            assertThat(Float.isNaN(tuple.floatValue(columnName)), is(true));
+            assertThat(Double.isNaN(tuple.doubleValue(columnName)), is(true));
+
+            assertThat(Float.isNaN(tuple.floatValue(0)), is(true));
+            assertThat(Double.isNaN(tuple.doubleValue(0)), is(true));
+        }
+
+        // Positive infinity
+        {
+            Tuple tuple = createTupleOfSingleColumn(ColumnType.FLOAT, 
columnName, Double.POSITIVE_INFINITY);
+
+            assertThat(tuple.floatValue(columnName), 
is(Float.POSITIVE_INFINITY));
+            assertThat(tuple.doubleValue(columnName), 
is(Double.POSITIVE_INFINITY));
+
+            assertThat(tuple.floatValue(0), is(Float.POSITIVE_INFINITY));
+            assertThat(tuple.doubleValue(0), is(Double.POSITIVE_INFINITY));
+        }
+
+        // Negative infinity
+        {
+            Tuple tuple = createTupleOfSingleColumn(ColumnType.FLOAT, 
columnName, Double.NEGATIVE_INFINITY);

Review Comment:
   Fixed



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