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()));
}
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()));
}
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()));
}
Aggregations