in src/main/java/org/apache/datasketches/pig/quantiles/UnionItemsSketch.java [121:139]
public Tuple exec(final Tuple inputTuple) throws IOException {
//The exec is a stateless function. It operates on the input and returns a result.
if (inputTuple != null && inputTuple.size() > 0) {
final ItemsUnion<T> union = this.k_ > 0
? ItemsUnion.getInstance(this.k_, this.comparator_)
: ItemsUnion.getInstance(this.comparator_);
final DataBag bag = (DataBag) inputTuple.get(0);
updateUnion(bag, union, this.comparator_, this.serDe_);
final ItemsSketch<T> resultSketch = union.getResultAndReset();
if (resultSketch != null) {
return tupleFactory_.newTuple(new DataByteArray(resultSketch.toByteArray(this.serDe_)));
}
}
// return empty sketch
final ItemsSketch<T> sketch = this.k_ > 0
? ItemsSketch.getInstance(this.k_, this.comparator_)
: ItemsSketch.getInstance(this.comparator_);
return tupleFactory_.newTuple(new DataByteArray(sketch.toByteArray(this.serDe_)));
}