I am using the RethinkDBJava driver and wanted to calculate the average deviation for each value of a specific field.
So, I wrote this code:
public static ReqlExpr avgdev(ReqlExpr expr, String field) {
return expr.map(
entry -> entry.g("parent_document").g(field).sub(expr.avg(row -> row.g("documents").g(field)))
);
}
As you can see, the average value is calculated several times. For such calculations, will RethinkDB automatically make sure that the average is calculated only once, or should I manually calculate the average once, and then use it to calculate the deviation?
I ask about this because the design pattern I use can change significantly in this situation.
source
share