@UdafFactory(description = "Compute average of column with type Long.",
      aggregateSchema = "STRUCT<SUM bigint, COUNT bigint>")
  public static TableUdaf<Long, Struct, Double> averageLong() {
    return getAverageImplementation(
        0L,
        STRUCT_LONG,
        (sum, newValue) -> sum.getInt64(SUM) + newValue,
        (sum, count) -> sum.getInt64(SUM) / count,
        (sum1, sum2) -> sum1.getInt64(SUM) + sum2.getInt64(SUM),
        (sum, valueToUndo) -> sum.getInt64(SUM) - valueToUndo);
  }
@Test
  public void shouldAggregateLongs() {
    final TableUdaf<Long, Struct, Double> udaf = AverageUdaf.averageLong();
    Struct agg = udaf.initialize();
    final Long[] values = new Long[] {1L, 1L, 1L, 1L, 1L};
    for (final Long thisValue : values) {
      agg = udaf.aggregate(thisValue, agg);
    }
    assertThat(5L, equalTo(agg.getInt64("COUNT")));
    assertThat(5L, equalTo(agg.getInt64("SUM")));
  }