class AverageUdaf {

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

  private  AverageUdaf();

}