avg() on BigDecimal column hits SqlFunctions.divide(BigDeciaml, BigDecimal), which further calls BigDecimal.divide(BigDecimal). This method will throw exception when the result has infinite digits after the decimal point, e.g. 10/9=1.11111...
The stack is as follows:
Alternatively, divide(BigDecimal divisor, MathContext mc) should be called instead, so BigDecimal knows the precision and rounding mode to handle the infinite number.