in src/main/java/org/apache/datasketches/pig/tuple/ArrayOfDoublesSketchToEstimates.java [45:68]
public Tuple exec(final Tuple input) throws IOException {
if (input == null || input.size() == 0) {
return null;
}
final DataByteArray dba = (DataByteArray) input.get(0);
final ArrayOfDoublesSketch sketch = ArrayOfDoublesSketches.wrapSketch(Memory.wrap(dba.get()));
final double[] estimates = new double[sketch.getNumValues() + 1];
estimates[0] = sketch.getEstimate();
if (sketch.getRetainedEntries() > 0) { // remove unnecessary check when version of sketches-core > 0.4.0
final ArrayOfDoublesSketchIterator it = sketch.iterator();
while (it.next()) {
final double[] values = it.getValues();
for (int i = 0; i < sketch.getNumValues(); i++) {
estimates[i + 1] += values[i];
}
}
for (int i = 0; i < sketch.getNumValues(); i++) {
estimates[i + 1] /= sketch.getTheta();
}
}
return Util.doubleArrayToTuple(estimates);
}