@Override
    public void merge(AggregationBuffer agg, Object partial) throws HiveException {
      if(partial == null) {
        return;
      }
      PercentileAggBuf myagg = (PercentileAggBuf) agg;
      List partialHistogram = (List) loi.getList(partial);
      DoubleObjectInspector doi = (DoubleObjectInspector)loi.getListElementObjectInspector();

      // remove requested quantiles from the head of the list
      int nquantiles = (int) doi.get(partialHistogram.get(0));
      if(nquantiles > 0) {
        myagg.quantiles = new double[nquantiles];
        for(int i = 1; i <= nquantiles; i++) {
          myagg.quantiles[i-1] = doi.get(partialHistogram.get(i));
        }
        partialHistogram.subList(0, nquantiles+1).clear();
      } else {
        partialHistogram.subList(0, 1).clear();
      }

      // merge histograms
      myagg.histogram.merge(partialHistogram, doi);
    }
Construct a histogram using the algorithm described by Ben-Haim and Tom-Tov, and then
use it to compute an approximate percentile value.
ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFPercentileApprox.java