raminqaf commented on code in PR #29323:
URL: https://github.com/apache/flink/pull/29323#discussion_r4131456837
##########
flink-core/src/main/java/org/apache/flink/types/variant/BinaryVariantInternalBuilder.java:
##########
@@ -271,6 +276,33 @@ public void appendDecimal(BigDecimal d) {
}
}
+ // The variant spec requires a scale in [0, 38] and a precision of at most
38.
+ private static BigDecimal toVariantDecimal(BigDecimal d) {
+ BigDecimal result = d;
+ if (d.scale() < 0) {
+ // A non-zero value with a scale below -38 has more than 38 digits
after rescaling.
+ // Reject it upfront because setScale is expensive for huge
exponents like 1e999999999.
+ if (d.signum() != 0 && d.scale() < -MAX_DECIMAL16_PRECISION) {
+ throw decimalOutOfRange(d);
+ }
+ result = d.setScale(0);
Review Comment:
Just add a one line of comment on top and say that for for a negative scale
the result is precision - scale. So in the case of `12345e34` is 5 - (-34) =
39.
--
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]