package com.facebook.presto;

import static com.facebook.presto.SizeOf.SIZE_OF_LONG;

public class SumAggregation
        implements AggregationFunction
{
    private long sum;

    @Override
    public TupleInfo getTupleInfo()
    {
        return new TupleInfo(TupleInfo.Type.FIXED_INT_64);
    }

    @Override
    public void add(ValueBlock values, PositionBlock relevantPositions)
    {
        ValueBlock filtered = values.filter(relevantPositions);

        for (Tuple value : filtered) {
            sum += value.getLong(0);
        }
    }

    @Override
    public Tuple evaluate()
    {
        Slice slice = Slices.allocate(SIZE_OF_LONG);
        slice.setLong(0, sum);
        return new Tuple(slice, getTupleInfo());
    }
}

@@ -27,64 +27,8 @@
 o;%0A%0A
-import static com.facebook.presto.SizeOf.SIZE_OF_LONG;%0A%0A
 publ
@@ -547,130 +547,92 @@
     
-Slice slice = Slices.allocate(SIZE_OF_LONG);%0A        slice.setLong(0, sum);%0A        return new Tuple(slice, getTupleInfo()
+return getTupleInfo().builder()%0A                .append(sum)%0A                .build(
 );%0A 

use tuple builder