slinkydeveloper commented on a change in pull request #17800:
URL: https://github.com/apache/flink/pull/17800#discussion_r750220364
##########
File path:
flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/data/binary/BinaryStringDataUtil.java
##########
@@ -525,56 +545,102 @@ public static Integer toInt(BinaryStringData str) {
while (i < sizeInBytes) {
byte currentByte = tmpBytes[i];
if (currentByte < '0' || currentByte > '9') {
- return null;
+ throw numberFormatExceptionFor(str, "INT", "Invalid character
found");
}
i++;
}
if (!negative) {
result = -result;
if (result < 0) {
- return null;
+ throw numberFormatExceptionFor(str, "INT", "Overflow");
}
}
return result;
}
- public static Short toShort(BinaryStringData str) {
- Integer intValue = toInt(str);
- if (intValue != null) {
- short result = intValue.shortValue();
- if (result == intValue) {
- return result;
- }
+ public static short toShort(BinaryStringData str) throws TableException {
+ int intValue = toInt(str);
+ short result = (short) intValue;
+ if (result == intValue) {
+ return result;
}
- return null;
+ throw numberFormatExceptionFor(str, "SHORT", "Overflow");
}
- public static Byte toByte(BinaryStringData str) {
- Integer intValue = toInt(str);
- if (intValue != null) {
- byte result = intValue.byteValue();
- if (result == intValue) {
- return result;
- }
+ public static byte toByte(BinaryStringData str) throws TableException {
+ int intValue = toInt(str);
+ byte result = (byte) intValue;
+ if (result == intValue) {
+ return result;
}
- return null;
+ throw numberFormatExceptionFor(str, "BYTE", "Overflow");
}
- public static Double toDouble(BinaryStringData str) {
+ public static double toDouble(BinaryStringData str) throws TableException {
try {
- return Double.valueOf(str.toString());
+ return Double.parseDouble(str.toString());
} catch (NumberFormatException e) {
- return null;
+ throw new TableException("Cannot parse STRING to DOUBLE", e);
}
}
- public static Float toFloat(BinaryStringData str) {
+ public static float toFloat(BinaryStringData str) throws TableException {
try {
- return Float.valueOf(str.toString());
+ return Float.parseFloat(str.toString());
} catch (NumberFormatException e) {
- return null;
+ throw new TableException("Cannot parse STRING to FLOAT", e);
Review comment:
Same as https://github.com/apache/flink/pull/17800#discussion_r750220243
--
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]