public Tuple exec()

in src/main/java/org/apache/datasketches/pig/quantiles/DataToItemsSketch.java [130:153]


  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);
      for (final Tuple innerTuple: bag) {
        final Object value = innerTuple.get(0);
        if (value != null) {
          union.update(extractValue(value));
        }
      }
      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_)));
  }