Search in sources :

Example 1 with Union

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

the class DataToSketchAlgebraicIntermediateFinal 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 Union<S> union = new Union<S>(sketchSize_, summarySetOps_);
    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 UpdatableSketch<U, S> sketch = sketchBuilder_.build();
            DataToSketch.updateSketch((DataBag) item, sketch);
            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 Sketch<S> incomingSketch = Util.deserializeSketchFromTuple(dataTuple, summaryDeserializer_);
            union.update(incomingSketch);
        } 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 : DEFAULT_NOMINAL_ENTRIES(com.yahoo.sketches.Util.DEFAULT_NOMINAL_ENTRIES) DataBag(org.apache.pig.data.DataBag) Sketch(com.yahoo.sketches.tuple.Sketch) UpdatableSketch(com.yahoo.sketches.tuple.UpdatableSketch) DataByteArray(org.apache.pig.data.DataByteArray) Union(com.yahoo.sketches.tuple.Union) Tuple(org.apache.pig.data.Tuple)

Example 2 with Union

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

the class UnionSketch 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 Union<S> union = new Union<S>(sketchSize_, summarySetOps_);
    updateUnion(bag, union, summaryDeserializer_);
    return Util.tupleFactory.newTuple(new DataByteArray(union.getResult().toByteArray()));
}
Also used : DataBag(org.apache.pig.data.DataBag) DEFAULT_NOMINAL_ENTRIES(com.yahoo.sketches.Util.DEFAULT_NOMINAL_ENTRIES) DataByteArray(org.apache.pig.data.DataByteArray) Union(com.yahoo.sketches.tuple.Union)

Example 3 with Union

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

the class UnionSketchAlgebraicIntermediateFinal 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 Union<S> union = new Union<S>(sketchSize_, summarySetOps_);
    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 (Tuple innerTuple : (DataBag) item) {
                final Sketch<S> incomingSketch = Util.deserializeSketchFromTuple(innerTuple, summaryDeserializer_);
                union.update(incomingSketch);
            }
        } else if (item instanceof DataByteArray) {
            // This is a sketch from a call to the Intermediate function
            // Add it to the current union.
            final Sketch<S> incomingSketch = Util.deserializeSketchFromTuple(dataTuple, summaryDeserializer_);
            union.update(incomingSketch);
        } 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 : DEFAULT_NOMINAL_ENTRIES(com.yahoo.sketches.Util.DEFAULT_NOMINAL_ENTRIES) DataBag(org.apache.pig.data.DataBag) Sketch(com.yahoo.sketches.tuple.Sketch) DataByteArray(org.apache.pig.data.DataByteArray) Union(com.yahoo.sketches.tuple.Union) Tuple(org.apache.pig.data.Tuple)

Aggregations

DEFAULT_NOMINAL_ENTRIES (com.yahoo.sketches.Util.DEFAULT_NOMINAL_ENTRIES)3 Union (com.yahoo.sketches.tuple.Union)3 DataBag (org.apache.pig.data.DataBag)3 DataByteArray (org.apache.pig.data.DataByteArray)3 Sketch (com.yahoo.sketches.tuple.Sketch)2 Tuple (org.apache.pig.data.Tuple)2 UpdatableSketch (com.yahoo.sketches.tuple.UpdatableSketch)1