You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by "ademakov (via GitHub)" <gi...@apache.org> on 2024/03/29 08:12:22 UTC

Re: [PR] IGNITE-21745 Optimize BigDecimal representation in BinaryTuple [ignite-3]

ademakov commented on code in PR #3493:
URL: https://github.com/apache/ignite-3/pull/3493#discussion_r1544215406


##########
modules/binary-tuple/src/main/java/org/apache/ignite/internal/binarytuple/BinaryTupleBuilder.java:
##########
@@ -315,8 +315,24 @@ public BinaryTupleBuilder appendNumber(BigInteger value) {
      * @return {@code this} for chaining.
      */
     public BinaryTupleBuilder appendDecimalNotNull(BigDecimal value, int scale) {
-        // TODO IGNITE-21745: Inefficient serialization, many bytes wasted to store small values when scale is big.
-        putBytes(value.setScale(scale, RoundingMode.HALF_UP).unscaledValue().toByteArray());
+        if (value.scale() > scale) {
+            value = value.setScale(scale, RoundingMode.HALF_UP);
+        }
+
+        value = value.stripTrailingZeros();
+
+        // See CatalogUtils.MAX_DECIMAL_SCALE = Short.MAX_VALUE
+        if (value.scale() > Short.MAX_VALUE) {
+            throw new BinaryTupleFormatException("Decimal scale is too large: " + value.scale() + " > " + Short.MAX_VALUE);
+        }
+
+        if (value.scale() < Short.MIN_VALUE) {
+            throw new BinaryTupleFormatException("Decimal scale is too small: " + value.scale() + " < " + Short.MIN_VALUE);
+        }

Review Comment:
   Can there be a situation when `scale()` fits the range before `stripTrailingZeros()` and doesn't after it?



-- 
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: notifications-unsubscribe@ignite.apache.org

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