hansva opened a new issue, #9296:
URL: https://github.com/apache/hop/issues/9296
### Apache Hop version?
2.20.0
### Java version?
21
### Operating system
Other
### What happened?
In the Row denormaliser, a target field of type BigNumber with aggregation
Average fails the transform whenever a group's average has no exact decimal
form, for example 1/3:
java.lang.ArithmeticException: Non-terminating decimal expansion; no
exact representable decimal result.
`Denormaliser.buildResult()` divides the sum by the count with
`BigDecimal.divide(BigDecimal)`. That method has no rounding, so it throws
unless the quotient is an exact decimal. Averages like 3/2 = 1.5 work, which is
why the failure depends on the data: a pipeline can run for months and then
fail on the first group whose average repeats.
Integer and Number averages are not affected: they use `/` on `long` and
`double`.
### Steps to reproduce
1. Input rows for one group key with the values `1`, `0` and `0` (sum 1,
count 3).
2. Row denormaliser with a target field of type BigNumber and aggregation
Average on that value.
3. Run the pipeline: the transform fails with the `ArithmeticException`
above instead of writing `0.333…`.
### Proposed fix
Divide with `MathContext.DECIMAL128` (34 significant digits, rounding half
even):
case BigDecimal bd -> bd.divide(BigDecimal.valueOf(count),
MathContext.DECIMAL128);
Exact averages give the same value as before. Averages that used to fail now
return the quotient rounded to 34 significant digits.
A test in `DenormaliserTest` averages a sum of 1 over a count of 3 and
expects `1 / 3` to 34 digits instead of an exception.
### Issue Priority
Priority: 3
### Issue Component
Component: Transforms
--
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]