public Tuple exec()

in src/main/java/org/apache/datasketches/pig/tuple/UnionArrayOfDoublesSketchAlgebraicIntermediateFinal.java [63:98]


  public Tuple exec(final Tuple inputTuple) throws IOException {
    if (this.isFirstCall_) {
      // this is to see in the log which way was used by Pig
      Logger.getLogger(getClass()).info("algebraic is used");
      this.isFirstCall_ = false;
    }
    final ArrayOfDoublesUnion union =
        new ArrayOfDoublesSetOperationBuilder().setNominalEntries(this.sketchSize_)
          .setNumberOfValues(this.numValues_).buildUnion();

    final DataBag bag = (DataBag) inputTuple.get(0);
    if (bag == null) {
      throw new IllegalArgumentException("InputTuple.Field0: Bag may not be null");
    }

    for (final Tuple dataTuple: bag) {
      final Object item = dataTuple.get(0);
      if (item instanceof DataBag) {
        // this is from a prior call to the initial function, so there is a nested bag.
        for (final Tuple innerTuple: (DataBag) item) {
          final DataByteArray dba = (DataByteArray) innerTuple.get(0);
          union.union(ArrayOfDoublesSketches.wrapSketch(Memory.wrap(dba.get())));
        }
      } else if (item instanceof DataByteArray) {
        // This is a sketch from a call to the Intermediate function
        // Add it to the current union
        final DataByteArray dba = (DataByteArray) item;
        union.union(ArrayOfDoublesSketches.wrapSketch(Memory.wrap(dba.get())));
      } else {
        // we should never get here.
        throw new IllegalArgumentException("InputTuple.Field0: Bag contains unrecognized types: "
            + item.getClass().getName());
      }
    }
    return Util.tupleFactory.newTuple(new DataByteArray(union.getResult().toByteArray()));
  }