Will the mapping in RethinkDB compute the same thing multiple times for the same value?

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.

+4
source share
1 answer

RethinkDB . do ( - expr.avg(...).do(avg -> expr.map(...))).

+2

Source: https://habr.com/ru/post/1624419/


All Articles