in src/main/java/org/apache/datasketches/hive/tuple/DoubleSummarySketchToPercentileUDF.java [57:71]
public Double evaluate(final BytesWritable serializedSketch, final double percentile) {
if (serializedSketch == null) { return null; }
if ((percentile < 0) || (percentile > 100)) {
throw new IllegalArgumentException("percentile must be between 0 and 100");
}
final Sketch<DoubleSummary> sketch =
Sketches.heapifySketch(BytesWritableHelper.wrapAsMemory(serializedSketch), SUMMARY_DESERIALIZER);
if (sketch.isEmpty()) { return Double.NaN; }
final UpdateDoublesSketch qs = DoublesSketch.builder().setK(QUANTILES_SKETCH_K).build();
final TupleSketchIterator<DoubleSummary> it = sketch.iterator();
while (it.next()) {
qs.update(it.getSummary().getValue());
}
return qs.getQuantile(percentile / 100);
}