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

    return getAverageImplementation(
        0,
        STRUCT_INT,
        (sum, newValue) -> sum.getInt32(SUM) + newValue,
        (sum, count) -> sum.getInt32(SUM) / count,
        (sum1, sum2) -> sum1.getInt32(SUM) + sum2.getInt32(SUM),
        (sum, valueToUndo) -> sum.getInt32(SUM) - valueToUndo);
  }
@Test
  public void shouldAverageInts() {
    final TableUdaf<Integer, Struct, Double> udaf = AverageUdaf.averageInt();
    Struct agg = udaf.initialize();
    final int[] values = new int[] {1, 1, 1, 1, 1};
    for (final int thisValue : values) {
      agg = udaf.aggregate(thisValue, agg);
    }
    final double avg = udaf.map(agg);

    assertThat(1.0, equalTo(avg));
  }