Skip to content

Commit

Permalink
Merge pull request #14982: [BEAM-12471] Fixes NumberFormatException
Browse files Browse the repository at this point in the history
  • Loading branch information
iemejia authored Jun 10, 2021
2 parents 67164a1 + 525d0f8 commit 815e2c9
Showing 1 changed file with 3 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ public static Object autoCastField(Schema.Field field, Object rawObj) {
&& ((rawObj instanceof String)
|| (rawObj instanceof BigDecimal && type.getTypeName() != TypeName.DECIMAL))) {
String raw = rawObj.toString();
if (raw.trim().isEmpty()) {
return null;
}
switch (type.getTypeName()) {
case BYTE:
return Byte.valueOf(raw);
Expand All @@ -154,16 +157,10 @@ public static Object autoCastField(Schema.Field field, Object rawObj) {
case INT32:
return Integer.valueOf(raw);
case INT64:
if (raw.equals("")) {
return null;
}
return Long.valueOf(raw);
case FLOAT:
return Float.valueOf(raw);
case DOUBLE:
if (raw.equals("")) {
return null;
}
return Double.valueOf(raw);
default:
throw new UnsupportedOperationException(
Expand Down

0 comments on commit 815e2c9

Please sign in to comment.