Search in sources :

Example 1 with DoublesSketchBuilder

use of com.yahoo.sketches.quantiles.DoublesSketchBuilder in project sketches-pig by DataSketches.

the class ArrayOfDoublesSketchToQuantilesSketch method exec.

@Override
public DataByteArray exec(final Tuple input) throws IOException {
    if ((input == null) || (input.size() == 0)) {
        return null;
    }
    final DataByteArray dba = (DataByteArray) input.get(0);
    final ArrayOfDoublesSketch sketch = ArrayOfDoublesSketches.wrapSketch(Memory.wrap(dba.get()));
    int column = 1;
    if (input.size() > 1) {
        column = (int) input.get(1);
        if ((column < 1) || (column > sketch.getNumValues())) {
            throw new IllegalArgumentException("Column number out of range. The given sketch has " + sketch.getNumValues() + " columns");
        }
    }
    final DoublesSketchBuilder builder = DoublesSketch.builder();
    if (k > 0) {
        builder.setK(k);
    }
    final UpdateDoublesSketch qs = builder.build();
    final ArrayOfDoublesSketchIterator it = sketch.iterator();
    while (it.next()) {
        qs.update(it.getValues()[column - 1]);
    }
    return new DataByteArray(qs.compact().toByteArray());
}
Also used : ArrayOfDoublesSketchIterator(com.yahoo.sketches.tuple.ArrayOfDoublesSketchIterator) UpdateDoublesSketch(com.yahoo.sketches.quantiles.UpdateDoublesSketch) DoublesSketchBuilder(com.yahoo.sketches.quantiles.DoublesSketchBuilder) DataByteArray(org.apache.pig.data.DataByteArray) ArrayOfDoublesSketch(com.yahoo.sketches.tuple.ArrayOfDoublesSketch)

Aggregations

DoublesSketchBuilder (com.yahoo.sketches.quantiles.DoublesSketchBuilder)1 UpdateDoublesSketch (com.yahoo.sketches.quantiles.UpdateDoublesSketch)1 ArrayOfDoublesSketch (com.yahoo.sketches.tuple.ArrayOfDoublesSketch)1 ArrayOfDoublesSketchIterator (com.yahoo.sketches.tuple.ArrayOfDoublesSketchIterator)1 DataByteArray (org.apache.pig.data.DataByteArray)1