vinishjail97 commented on code in PR #617:
URL: https://github.com/apache/incubator-xtable/pull/617#discussion_r1904672353


##########
xtable-core/src/main/java/org/apache/xtable/hudi/HudiFileStatsExtractor.java:
##########
@@ -200,14 +201,16 @@ private static ColumnStat getColumnStatFromHudiStat(
     Comparable<?> minValue = 
HoodieAvroUtils.unwrapAvroValueWrapper(columnStats.getMinValue());
     Comparable<?> maxValue = 
HoodieAvroUtils.unwrapAvroValueWrapper(columnStats.getMaxValue());
     if (field.getSchema().getDataType() == InternalType.DECIMAL) {
+      int scale =
+          (int) 
field.getSchema().getMetadata().get(InternalSchema.MetadataKey.DECIMAL_SCALE);
       minValue =
           minValue instanceof ByteBuffer
-              ? convertBytesToBigDecimal((ByteBuffer) minValue, 
DECIMAL_WRAPPER_SCALE)
-              : minValue;
+              ? convertBytesToBigDecimal((ByteBuffer) minValue, scale)
+              : ((BigDecimal) minValue).setScale(scale, RoundingMode.CEILING);
       maxValue =
           maxValue instanceof ByteBuffer
-              ? convertBytesToBigDecimal((ByteBuffer) maxValue, 
DECIMAL_WRAPPER_SCALE)
-              : maxValue;
+              ? convertBytesToBigDecimal((ByteBuffer) maxValue, scale)
+              : ((BigDecimal) maxValue).setScale(scale, RoundingMode.CEILING);

Review Comment:
   Same comment on choosing `CEILING` above `HALF_UP` for RoundingMode.



##########
xtable-core/src/main/java/org/apache/xtable/delta/DeltaValueConverter.java:
##########
@@ -242,18 +244,11 @@ private static Object castObjectToInternalType(Object 
value, InternalType valueT
     return value;
   }
 
-  private static BigDecimal numberTypeToBigDecimal(Object value) {
+  private static BigDecimal numberTypeToBigDecimal(Object value, 
InternalSchema schema) {
     // BigDecimal is parsed as Integer, Long, BigInteger and double if none of 
the above.
-    if (value instanceof Integer) {
-      return BigDecimal.valueOf((Integer) value);
-    } else if (value instanceof Long) {
-      return BigDecimal.valueOf((Long) value);
-    } else if (value instanceof BigInteger) {
-      return new BigDecimal((BigInteger) value);
-    } else if (value instanceof Double) {
-      return BigDecimal.valueOf((Double) value);
-    } else {
-      return (BigDecimal) value;
-    }
+    int precision = (int) 
schema.getMetadata().get(InternalSchema.MetadataKey.DECIMAL_PRECISION);
+    int scale = (int) 
schema.getMetadata().get(InternalSchema.MetadataKey.DECIMAL_SCALE);
+    return new BigDecimal(String.valueOf(value), new MathContext(precision))
+        .setScale(scale, RoundingMode.CEILING);

Review Comment:
   Should this be `RoundingMode.HALF_UP` by default ? Or any reason for 
choosing RoundingMode.CEILING ? 



##########
xtable-core/src/main/java/org/apache/xtable/delta/DeltaValueConverter.java:
##########
@@ -242,18 +244,11 @@ private static Object castObjectToInternalType(Object 
value, InternalType valueT
     return value;
   }
 
-  private static BigDecimal numberTypeToBigDecimal(Object value) {
+  private static BigDecimal numberTypeToBigDecimal(Object value, 
InternalSchema schema) {
     // BigDecimal is parsed as Integer, Long, BigInteger and double if none of 
the above.

Review Comment:
   Do we still need this comment ?     
   `// BigDecimal is parsed as Integer, Long, BigInteger and double if none of 
the above.`



-- 
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: commits-unsubscr...@xtable.apache.org

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

Reply via email to