Skip to content

Commit

Permalink
chore: Skip creation of BigDecimal during getDecimal call
Browse files Browse the repository at this point in the history
  • Loading branch information
viirya committed Jul 18, 2024
1 parent b558063 commit 0265db5
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions common/src/main/java/org/apache/comet/vector/CometVector.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0265db5

Please sign in to comment.