diff --git a/sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/schema/BeamTableUtils.java b/sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/schema/BeamTableUtils.java index 205196911188..00bf2ce8e8d0 100644 --- a/sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/schema/BeamTableUtils.java +++ b/sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/schema/BeamTableUtils.java @@ -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); @@ -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(