@UdafFactory(description = "sum double values in a list into a single double")
  public static TableUdaf<List<Double>, Double, Double> sumDoubleList() {
    return new TableUdaf<List<Double>, Double, Double>() {

      @Override
      public Double initialize() {
        return 0.0;
      }

      @Override
      public Double aggregate(final List<Double> valueToAdd, final Double aggregateValue) {
        if (valueToAdd == null) {
          return aggregateValue;
        }
        return aggregateValue + sumList(valueToAdd);
      }

      @Override
      public Double merge(final Double aggOne, final Double aggTwo) {
        return aggOne + aggTwo;
      }

      @Override
      public Double map(final Double agg) {
        return agg;
      }

      @Override
      public Double undo(final List<Double> valueToUndo, final Double aggregateValue) {
        if (valueToUndo == null) {
          return aggregateValue;
        }
        return aggregateValue - sumList(valueToUndo);
      }

      private double sumList(final List<Double> list) {
        return sum(list, initialize(), Double::sum);
      }
    };
  }
@Test
  public void shouldSumDoubleList() {
    final TableUdaf<List<Double>, Double, Double>  udaf = ListSumUdaf.sumDoubleList();
    final Double[] values = new Double[] {1.0, 1.0, 1.0, 1.0, 1.0};
    final List<Double> list = Arrays.asList(values);
    final Double sum = udaf.aggregate(list, 0.0);

    assertThat(5.0, equalTo(sum));
  }