@Override
    public void merge(AggregationBuffer agg, Object partial) throws HiveException {
      if (partial == null) {
        return;
      }

      Object objCounts = soi.getStructFieldData(partial, countsField);
      Object objPercentiles = soi.getStructFieldData(partial, percentilesField);
      Object objIsAscending = soi.getStructFieldData(partial, isAscendingField);

      Map<U, LongWritable> counts = (Map<U, LongWritable>) countsOI.getMap(objCounts);
      List<DoubleWritable> percentiles =
          (List<DoubleWritable>) percentilesOI.getList(objPercentiles);

      if (counts == null || percentiles == null) {
        return;
      }

      PercentileAgg percAgg = (PercentileAgg) agg;

      if (percAgg.percentiles == null) {
        percAgg.percentiles = new ArrayList<DoubleWritable>(percentiles);
      }
      percAgg.isAscending = ((BooleanWritable)objIsAscending).get();

      for (Map.Entry<U, LongWritable> e : counts.entrySet()) {
        increment(percAgg, e.getKey(), e.getValue().get());
      }
    }
A state class to store intermediate aggregation results.
ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFPercentileCont.java