Hi,
I am trying to use the group by aggregation function. On my query:
query.from(qModel).where(predicateBuilder)
.transform(GroupBy.groupBy(qModel.field1)
.as(GroupBy.avg(qReservation.field2))).entrySet()
I get the following exception:
java.lang.ArithmeticException: Non-terminating decimal expansion; no exact representable decimal result.
at java.math.BigDecimal.divide(BigDecimal.java:1690)
at com.querydsl.core.group.GAvg$1.get(GAvg.java:46)
at com.querydsl.core.group.GAvg$1.get(GAvg.java:32)
at com.querydsl.core.group.GroupImpl.get(GroupImpl.java:70)
at com.querydsl.core.group.GroupImpl.getOne(GroupImpl.java:115)
at com.querydsl.core.group.GroupByBuilder$1.transform(GroupByBuilder.java:92)
at com.querydsl.core.group.GroupByMap.transform(GroupByMap.java:72)
at com.querydsl.core.group.GroupByMap.transform(GroupByMap.java:35)
at com.querydsl.core.support.FetchableQueryBase.transform(FetchableQueryBase.java:55)
This seems to be pointing at the fact that the division at this line:
"BigDecimal avg = sum.divide(BigDecimal.valueOf(count));"
does not provide precision and rounding which may be causing this error.
Any workarounds for this?
I would actually prefer doing Aggregation on the database (Postgres) rather than in memory aggregation but from the doc:
it seems aggregation is done in memory:
"The com.querydsl.core.group.GroupBy
class provides aggregation functionality which can be used to aggregate query results in memory."
I'm pretty new to querydsl.
It would be great if someone could help me with this.