use of com.yahoo.sketches.tuple.ArrayOfDoublesUpdatableSketchBuilder in project sketches-pig by DataSketches.
the class ArrayOfDoublesSketchToEstimatesTest method normalCase.
@Test
public void normalCase() throws Exception {
EvalFunc<Tuple> func = new ArrayOfDoublesSketchToEstimates();
ArrayOfDoublesUpdatableSketch sketch = new ArrayOfDoublesUpdatableSketchBuilder().build();
int iterations = 100000;
for (int i = 0; i < iterations; i++) sketch.update(i, new double[] { 1 });
for (int i = 0; i < iterations; i++) sketch.update(i, new double[] { 1 });
Tuple inputTuple = PigUtil.objectsToTuple(new DataByteArray(sketch.compact().toByteArray()));
Tuple resultTuple = func.exec(inputTuple);
Assert.assertNotNull(resultTuple);
Assert.assertEquals(resultTuple.size(), 2);
Assert.assertEquals((double) resultTuple.get(0), iterations, iterations * 0.03);
Assert.assertEquals((double) resultTuple.get(1), 2 * iterations, 2 * iterations * 0.03);
}
use of com.yahoo.sketches.tuple.ArrayOfDoublesUpdatableSketchBuilder in project sketches-pig by DataSketches.
the class ArrayOfDoublesSketchToMeansTest method emptyInputSketch.
@Test
public void emptyInputSketch() throws Exception {
EvalFunc<Tuple> func = new ArrayOfDoublesSketchToMeans();
ArrayOfDoublesUpdatableSketch sketch = new ArrayOfDoublesUpdatableSketchBuilder().build();
Tuple inputTuple = PigUtil.objectsToTuple(new DataByteArray(sketch.compact().toByteArray()));
Tuple resultTuple = func.exec(inputTuple);
Assert.assertNull(resultTuple);
}
use of com.yahoo.sketches.tuple.ArrayOfDoublesUpdatableSketchBuilder in project sketches-pig by DataSketches.
the class ArrayOfDoublesSketchToNumberOfRetainedEntriesTest method nonEmptyInputSketch.
@Test
public void nonEmptyInputSketch() throws Exception {
EvalFunc<Integer> func = new ArrayOfDoublesSketchToNumberOfRetainedEntries();
ArrayOfDoublesUpdatableSketch sketch = new ArrayOfDoublesUpdatableSketchBuilder().build();
sketch.update(1, new double[] { 0 });
Integer result = func.exec(tupleFactory.newTuple(new DataByteArray(sketch.compact().toByteArray())));
Assert.assertNotNull(result);
Assert.assertEquals((int) result, 1);
}
use of com.yahoo.sketches.tuple.ArrayOfDoublesUpdatableSketchBuilder in project sketches-pig by DataSketches.
the class ArrayOfDoublesSketchToQuantilesSketchTest method nonEmptyInputSketchWithTwoColumnsExplicitK.
@Test
public void nonEmptyInputSketchWithTwoColumnsExplicitK() throws Exception {
int k = 256;
EvalFunc<DataByteArray> func = new ArrayOfDoublesSketchToQuantilesSketch(Integer.toString(k));
ArrayOfDoublesUpdatableSketch sketch = new ArrayOfDoublesUpdatableSketchBuilder().setNumberOfValues(2).build();
sketch.update(1, new double[] { 1.0, 2.0 });
sketch.update(2, new double[] { 10.0, 20.0 });
DataByteArray result = func.exec(tupleFactory.newTuple(Arrays.asList(new DataByteArray(sketch.compact().toByteArray()), 2)));
Assert.assertNotNull(result);
DoublesSketch quantilesSketch = DoublesSketch.wrap(Memory.wrap(result.get()));
Assert.assertFalse(quantilesSketch.isEmpty());
Assert.assertEquals(quantilesSketch.getK(), k);
Assert.assertEquals(quantilesSketch.getMinValue(), 2.0);
Assert.assertEquals(quantilesSketch.getMaxValue(), 20.0);
}
use of com.yahoo.sketches.tuple.ArrayOfDoublesUpdatableSketchBuilder in project sketches-pig by DataSketches.
the class ArrayOfDoublesSketchToQuantilesSketchTest method emptyInputSketch.
@Test
public void emptyInputSketch() throws Exception {
EvalFunc<DataByteArray> func = new ArrayOfDoublesSketchToQuantilesSketch();
ArrayOfDoublesUpdatableSketch sketch = new ArrayOfDoublesUpdatableSketchBuilder().build();
DataByteArray result = func.exec(tupleFactory.newTuple(new DataByteArray(sketch.compact().toByteArray())));
Assert.assertNotNull(result);
DoublesSketch quantilesSketch = DoublesSketch.wrap(Memory.wrap(result.get()));
Assert.assertTrue(quantilesSketch.isEmpty());
}
Aggregations