diff --git a/common/src/main/java/org/apache/comet/vector/CometVector.java b/common/src/main/java/org/apache/comet/vector/CometVector.java index 27f40bace9..6aae0383a9 100644 --- a/common/src/main/java/org/apache/comet/vector/CometVector.java +++ b/common/src/main/java/org/apache/comet/vector/CometVector.java @@ -79,14 +79,23 @@ public Decimal getDecimal(int i, int precision, int scale) { } else { byte[] bytes = getBinaryDecimal(i); BigInteger bigInteger = new BigInteger(bytes); - BigDecimal javaDecimal = new BigDecimal(bigInteger, scale); try { - return Decimal.apply(javaDecimal, precision, scale); + Decimal d = Decimal.apply(bigInteger); + boolean success = d.changePrecision(precision, scale); + if (!success) { + throw new ArithmeticException( + "Overflowing when convert " + + bigInteger + + " to decimal with precision: " + + precision + + " and scale: " + + scale); + } + return d; } catch (ArithmeticException e) { throw new ArithmeticException( "Cannot convert " - + javaDecimal - + " (bytes: " + + "(bytes: " + bytes + ", integer: " + bigInteger