@UdafFactory(description = "Compute average of column with type Double.",
      aggregateSchema = "STRUCT<SUM double, COUNT bigint>")
  public static TableUdaf<Double, Struct, Double> averageDouble() {

    return getAverageImplementation(
        0.0,
        STRUCT_DOUBLE,
        (sum, newValue) -> sum.getFloat64(SUM) + newValue,
        (sum, count) -> sum.getFloat64(SUM) / count,
        (sum1, sum2) -> sum1.getFloat64(SUM) + sum2.getFloat64(SUM),
        (sum, valueToUndo) -> sum.getFloat64(SUM) - valueToUndo);
  }
@Test
  public void shouldAverageDoubles() {
    final TableUdaf<Double, Struct, Double> udaf = AverageUdaf.averageDouble();
    Struct agg = udaf.initialize();
    final double[] values = new double[] {1.0, 1.0, 1.0, 1.0, 1.0};
    for (final double thisValue : values) {
      agg = udaf.aggregate(thisValue, agg);
    }
    final double avg = udaf.map(agg);

    assertThat(1.0, equalTo(avg));
  }