Search in sources :

Example 1 with ArrayOfDoublesUnion

use of com.yahoo.sketches.tuple.ArrayOfDoublesUnion in project sketches-pig by DataSketches.

the class UnionArrayOfDoublesSketchAlgebraicIntermediateFinal 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 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.update(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.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()));
}
Also used : ArrayOfDoublesUnion(com.yahoo.sketches.tuple.ArrayOfDoublesUnion) DataBag(org.apache.pig.data.DataBag) ArrayOfDoublesSetOperationBuilder(com.yahoo.sketches.tuple.ArrayOfDoublesSetOperationBuilder) DataByteArray(org.apache.pig.data.DataByteArray) Tuple(org.apache.pig.data.Tuple)

Example 2 with ArrayOfDoublesUnion

use of com.yahoo.sketches.tuple.ArrayOfDoublesUnion in project sketches-pig by DataSketches.

the class UnionArrayOfDoublesSketchBase 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("exec is used");
        isFirstCall_ = false;
    }
    if ((inputTuple == null) || (inputTuple.size() == 0)) {
        return null;
    }
    final DataBag bag = (DataBag) inputTuple.get(0);
    final ArrayOfDoublesUnion union = new ArrayOfDoublesSetOperationBuilder().setNominalEntries(sketchSize_).setNumberOfValues(numValues_).buildUnion();
    updateUnion(bag, union);
    return Util.tupleFactory.newTuple(new DataByteArray(union.getResult().toByteArray()));
}
Also used : DataBag(org.apache.pig.data.DataBag) ArrayOfDoublesUnion(com.yahoo.sketches.tuple.ArrayOfDoublesUnion) ArrayOfDoublesSetOperationBuilder(com.yahoo.sketches.tuple.ArrayOfDoublesSetOperationBuilder) DataByteArray(org.apache.pig.data.DataByteArray)

Example 3 with ArrayOfDoublesUnion

use of com.yahoo.sketches.tuple.ArrayOfDoublesUnion 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()));
}
Also used : ArrayOfDoublesUpdatableSketchBuilder(com.yahoo.sketches.tuple.ArrayOfDoublesUpdatableSketchBuilder) ArrayOfDoublesUnion(com.yahoo.sketches.tuple.ArrayOfDoublesUnion) DataBag(org.apache.pig.data.DataBag) ArrayOfDoublesUpdatableSketch(com.yahoo.sketches.tuple.ArrayOfDoublesUpdatableSketch) ArrayOfDoublesSetOperationBuilder(com.yahoo.sketches.tuple.ArrayOfDoublesSetOperationBuilder) DataByteArray(org.apache.pig.data.DataByteArray) Tuple(org.apache.pig.data.Tuple)

Aggregations

ArrayOfDoublesSetOperationBuilder (com.yahoo.sketches.tuple.ArrayOfDoublesSetOperationBuilder)3 ArrayOfDoublesUnion (com.yahoo.sketches.tuple.ArrayOfDoublesUnion)3 DataBag (org.apache.pig.data.DataBag)3 DataByteArray (org.apache.pig.data.DataByteArray)3 Tuple (org.apache.pig.data.Tuple)2 ArrayOfDoublesUpdatableSketch (com.yahoo.sketches.tuple.ArrayOfDoublesUpdatableSketch)1 ArrayOfDoublesUpdatableSketchBuilder (com.yahoo.sketches.tuple.ArrayOfDoublesUpdatableSketchBuilder)1