@Override
    public Object terminatePartial(AggregationBuffer agg) throws HiveException {
      NGramAggBuf myagg = (NGramAggBuf) agg;
      ArrayList<Text> result = myagg.nge.serialize();
      result.add(new Text(Integer.toString(myagg.n)));
      return result;
    }
A constant-space heuristic to estimate the top-k n-grams.
ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFnGrams.java