class AverageUdaf {

  @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);
  }

  private  AverageUdaf();

}