presto-main/src/main/java/io/prestosql/operator/aggregation/AggregationUtils.java/AggregationUtils/mergeVarianceState
class AggregationUtils:    public static void mergeVarianceState(VarianceState state, VarianceState otherState)
    {
        long count = otherState.getCount();
        double mean = otherState.getMean();
        double m2 = otherState.getM2();

        checkArgument(count >= 0, "count is negative");
        if (count == 0) {
            return;
        }
        long newCount = count + state.getCount();
        double newMean = ((count * mean) + (state.getCount() * state.getMean())) / (double) newCount;
        double delta = mean - state.getMean();
        state.setM2(state.getM2() + m2 + delta * delta * count * state.getCount() / (double) newCount);
        state.setCount(newCount);
        state.setMean(newMean);
    }