the-other-tim-brown commented on code in PR #617:
URL: https://github.com/apache/incubator-xtable/pull/617#discussion_r1904707189
##########
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:
I am going to switch this all to use `UNNECESSARY` where possible
--
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]