raminqaf commented on code in PR #29021:
URL: https://github.com/apache/flink/pull/29021#discussion_r3860400520


##########
flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/data/binary/BinaryStringDataUtil.java:
##########
@@ -574,11 +574,34 @@ public static byte toByte(BinaryStringData str) throws 
NumberFormatException {
     }
 
     public static double toDouble(BinaryStringData str) throws 
NumberFormatException {
-        return Double.parseDouble(str.toString());
+        return 
Double.parseDouble(normalizeFloatingPointSpecialValue(str.toString()));
     }
 
     public static float toFloat(BinaryStringData str) throws 
NumberFormatException {
-        return Float.parseFloat(str.toString());
+        return 
Float.parseFloat(normalizeFloatingPointSpecialValue(str.toString()));
+    }
+
+    /**
+     * Rewrites case-insensitive and abbreviated special values ({@code nan}, 
{@code inf}, {@code
+     * infinity}, with an optional sign on infinity) into the canonical tokens 
{@link
+     * Double#parseDouble} and {@link Float#parseFloat} accept. Any other 
input is returned
+     * unchanged.
+     */
+    private static String normalizeFloatingPointSpecialValue(String str) {
+        final String trimmed = str.trim();

Review Comment:
   Added two test for the trim case. Trim only takes the white spaces around 
the character and not between two characters. So the case `- infinity` is not 
valid and we get a `NumberFormatException`
   
   ```java
           // Only the trimmed token matches: surrounding whitespace is 
allowed, interior is not.
           assertThat(toDouble(fromString("  -infinity  
"))).isEqualTo(Double.NEGATIVE_INFINITY);
           assertThatThrownBy(() -> toFloat(fromString("-   Infinity")))
                   .isInstanceOf(NumberFormatException.class);
   ```



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