You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@avro.apache.org by GitBox <gi...@apache.org> on 2020/05/20 00:22:01 UTC

[GitHub] [avro] maccamlc commented on a change in pull request #884: AVRO-2837: DecimalConversion handling of scale and precision

maccamlc commented on a change in pull request #884:
URL: https://github.com/apache/avro/pull/884#discussion_r427673184



##########
File path: lang/java/avro/src/main/java/org/apache/avro/Conversions.java
##########
@@ -117,6 +115,25 @@ public GenericFixed toFixed(BigDecimal value, Schema schema, LogicalType type) {
 
       return new GenericData.Fixed(schema, bytes);
     }
+
+    private static BigDecimal validate(LogicalTypes.Decimal decimal, BigDecimal value) {
+      int scale = decimal.getScale();
+      int valueScale = value.scale();
+      if (valueScale > scale) {
+        throw new AvroTypeException("Cannot encode decimal with scale " + valueScale + " as scale " + scale);
+      } else if (valueScale < scale) {
+        value = value.setScale(scale, ROUND_UNNECESSARY);

Review comment:
       this would be a safe operation, but wondering if there is any best-practice to set behind a flag that can be enabled/disabled?




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

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