liu-du commented on a change in pull request #16926:
URL: https://github.com/apache/beam/pull/16926#discussion_r815375516



##########
File path: 
sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/bigquery/TableRowJsonCoder.java
##########
@@ -68,7 +73,17 @@ public long getEncodedElementByteSize(TableRow value) throws 
Exception {
   // FAIL_ON_EMPTY_BEANS is disabled in order to handle null values in
   // TableRow.
   private static final ObjectMapper MAPPER =
-      new ObjectMapper().disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
+      JsonMapper.builder()
+          .disable(SerializationFeature.FAIL_ON_EMPTY_BEANS)
+          .addModule(new JavaTimeModule())
+          // serialize Date/Time to string instead of floats
+          .configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false)
+          // serialize BigDecimal to string without scientific notation 
instead of floats
+          .configure(JsonGenerator.Feature.WRITE_BIGDECIMAL_AS_PLAIN, true)
+          .withConfigOverride(
+              BigDecimal.class,
+              it -> 
it.setFormat(JsonFormat.Value.forShape(JsonFormat.Shape.STRING)))

Review comment:
       I changed it because Jackson serializes BigDecimal as float by default, 
but floats are prone to lose precision. this can be avoided by serializing 
BigDecimal to string.
   
   The new configuration only changes how Jackson serialize TableRows, 
deserialization should continue to work since it's just deserializing plain 
json. Still, the in-flight BigDecimal (already serialized as floats) may need 
to be converted to protobuf String, for this I've added some code in 
`TableRowToStorageApiProto.scalarToProtoValue` to convert double/floats to 
String. I hope this should be enough to address backward compatibility?
   




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