ptupitsyn commented on code in PR #3493:
URL: https://github.com/apache/ignite-3/pull/3493#discussion_r1544298175
##########
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:
Added a test too (`BinaryTupleTest.maxDecimalScaleTest`) - it failed before
the fix and now works.
--
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]