You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by GitBox <gi...@apache.org> on 2022/12/12 17:50:30 UTC

[GitHub] [beam] lukecwik commented on a diff in pull request #24366: Improve Integer conversion in BigQueryIO's Storage Write API method.

lukecwik commented on code in PR #24366:
URL: https://github.com/apache/beam/pull/24366#discussion_r1046170338


##########
sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/bigquery/TableRowToStorageApiProto.java:
##########
@@ -590,9 +605,25 @@ private static void fieldDescriptorFromTableField(
     switch (schemaInformation.getType()) {
       case INT64:
         if (value instanceof String) {
-          return Long.valueOf((String) value);
+          try {
+            return Long.valueOf((String) value);
+          } catch (NumberFormatException e) {
+            throw new SingleValueConversionException(value, schemaInformation, e);
+          }
         } else if (value instanceof Integer || value instanceof Long) {
           return ((Number) value).longValue();
+        } else if (value instanceof BigDecimal) {
+          try {
+            return ((BigDecimal) value).longValueExact();
+          } catch (ArithmeticException e) {
+            throw new SingleValueConversionException(value, schemaInformation, e);
+          }
+        } else if( value instanceof BigInteger) {

Review Comment:
   ```suggestion
           } else if (value instanceof BigInteger) {
   ```



-- 
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: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org