qian0817 opened a new issue, #3146: URL: https://github.com/apache/parquet-java/issues/3146
### Describe the enhancement requested https://github.com/apache/parquet-java/blob/master/parquet-pig/src/main/java/org/apache/parquet/pig/convert/DecimalUtils.java ```java public static BigDecimal binaryToDecimal(Binary value, int precision, int scale) { /* * Precision <= 18 checks for the max number of digits for an unscaled long, * else treat with big integer conversion */ if (precision <= 18) { ByteBuffer buffer = value.toByteBuffer(); byte[] bytes = buffer.array(); int start = buffer.arrayOffset() + buffer.position(); int end = buffer.arrayOffset() + buffer.limit(); long unscaled = 0L; int i = start; while (i < end) { unscaled = (unscaled << 8 | bytes[i] & 0xff); i++; } int bits = 8 * (end - start); long unscaledNew = (unscaled << (64 - bits)) >> (64 - bits); if (unscaledNew <= -pow(10, 18) || unscaledNew >= pow(10, 18)) { return new BigDecimal(unscaledNew); } else { return BigDecimal.valueOf(unscaledNew / pow(10, scale)); } } else { return new BigDecimal(new BigInteger(value.getBytes()), scale); } } ``` If precision is less than 18, the condition `unscaledNew <= -pow(10, 18) || unscaledNew >= pow(10, 18)` can not be true, so we can remove the judgment logic here. Additionally, using `BigDecimal.valueOf(unscaledNew, scale)` is preferable over using `BigDecimal.valueOf(unscaledNew / pow(10, scale))`, as it does not convert the unscaled value to double. ### Component(s) _No response_ -- 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: issues-unsubscr...@parquet.apache.org.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@parquet.apache.org For additional commands, e-mail: issues-h...@parquet.apache.org