private ValueExtractor buildStatValueExtractor(final int idx) {
        final ValueExtractor extractor;
        extractor = (rs, arr, cache) -> {

            final double aggregatedValue;
            final long count;
            try {
                aggregatedValue = rs.getDouble(SQLStatisticNames.VALUE);
                count = rs.getLong(SQLStatisticNames.COUNT);
            } catch (SQLException e) {
                throw new RuntimeException("Error extracting count and value fields", e);
            }

            // the aggregateValue is sum of all values against that
            // key/time. We therefore need to get the
            // average using the count column
            final double averagedValue = count != 0
                    ? (aggregatedValue / count)
                    : 0;

            arr[idx] = ValDouble.create(averagedValue);
        };
        return extractor;
    }
Build a mapper function that will only extract the columns of interest from the resultSet row.
Assumes something external to the returned function will advance the resultSet
stroom-statistics/stroom-statistics-impl-sql/src/main/java/stroom/statistics/impl/sql/search/StatisticsSearchServiceImpl.java