use of com.yahoo.sketches.tuple.ArrayOfDoublesUpdatableSketchBuilder in project sketches-pig by DataSketches.
the class DataToArrayOfDoublesSketchAlgebraicIntermediateFinal method exec.
@Override
public Tuple exec(final Tuple inputTuple) throws IOException {
if (isFirstCall_) {
// this is to see in the log which way was used by Pig
Logger.getLogger(getClass()).info("algebraic is used");
isFirstCall_ = false;
}
final ArrayOfDoublesUnion union = new ArrayOfDoublesSetOperationBuilder().setNominalEntries(sketchSize_).setNumberOfValues(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 a bag from the Initial function.
// just insert each item of the tuple into the sketch
final ArrayOfDoublesUpdatableSketch sketch = new ArrayOfDoublesUpdatableSketchBuilder().setNominalEntries(sketchSize_).setSamplingProbability(samplingProbability_).setNumberOfValues(numValues_).build();
DataToArrayOfDoublesSketchBase.updateSketch((DataBag) item, sketch, numValues_);
union.update(sketch);
} else if (item instanceof DataByteArray) {
// This is a sketch from a prior call to the
// Intermediate function. merge it with the
// current sketch.
final DataByteArray dba = (DataByteArray) item;
union.update(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()));
}
use of com.yahoo.sketches.tuple.ArrayOfDoublesUpdatableSketchBuilder in project sketches-pig by DataSketches.
the class DataToArrayOfDoublesSketchBase method accumulate.
@Override
public void accumulate(final Tuple inputTuple) throws IOException {
if (isFirstCall_) {
// this is to see in the log which way was used by Pig
Logger.getLogger(getClass()).info("accumulate is used");
isFirstCall_ = false;
}
if (accumSketch_ == null) {
accumSketch_ = new ArrayOfDoublesUpdatableSketchBuilder().setNominalEntries(sketchSize_).setSamplingProbability(samplingProbability_).setNumberOfValues(numValues_).build();
}
if (inputTuple.size() != 1) {
throw new IllegalArgumentException("Input tuple must have 1 bag");
}
final DataBag bag = (DataBag) inputTuple.get(0);
updateSketch(bag, accumSketch_, numValues_);
}
Aggregations