use of com.yahoo.sketches.tuple.ArrayOfDoublesSketch in project sketches-pig by DataSketches.
the class UnionArrayOfDoublesSketchTest method accumulator.
@Test
public void accumulator() throws Exception {
Accumulator<Tuple> func = new UnionArrayOfDoublesSketch("4096", "1");
DataBag bag = BagFactory.getInstance().newDefaultBag();
{
ArrayOfDoublesUpdatableSketch sketch = new ArrayOfDoublesUpdatableSketchBuilder().build();
sketch.update(1, new double[] { 1.0 });
sketch.update(2, new double[] { 1.0 });
bag.add(PigUtil.objectsToTuple(new DataByteArray(sketch.compact().toByteArray())));
}
func.accumulate(PigUtil.objectsToTuple(bag));
bag = BagFactory.getInstance().newDefaultBag();
{
ArrayOfDoublesUpdatableSketch sketch = new ArrayOfDoublesUpdatableSketchBuilder().build();
sketch.update(1, new double[] { 1.0 });
sketch.update(2, new double[] { 1.0 });
bag.add(PigUtil.objectsToTuple(new DataByteArray(sketch.compact().toByteArray())));
}
func.accumulate(PigUtil.objectsToTuple(bag));
Tuple resultTuple = func.getValue();
Assert.assertNotNull(resultTuple);
Assert.assertEquals(resultTuple.size(), 1);
DataByteArray bytes = (DataByteArray) resultTuple.get(0);
Assert.assertTrue(bytes.size() > 0);
ArrayOfDoublesSketch sketch = ArrayOfDoublesSketches.heapifySketch(Memory.wrap(bytes.get()));
Assert.assertEquals(sketch.getEstimate(), 2.0, 0.0);
for (double[] values : sketch.getValues()) {
Assert.assertEquals(values[0], 2.0, 0.0);
}
}
use of com.yahoo.sketches.tuple.ArrayOfDoublesSketch in project sketches-pig by DataSketches.
the class UnionArrayOfDoublesSketchTest method accumulatorEmptyInputTuple.
@Test
public void accumulatorEmptyInputTuple() throws Exception {
Accumulator<Tuple> func = new UnionArrayOfDoublesSketch();
func.accumulate(TupleFactory.getInstance().newTuple());
Tuple resultTuple = func.getValue();
Assert.assertNotNull(resultTuple);
Assert.assertEquals(resultTuple.size(), 1);
DataByteArray bytes = (DataByteArray) resultTuple.get(0);
Assert.assertTrue(bytes.size() > 0);
ArrayOfDoublesSketch sketch = ArrayOfDoublesSketches.heapifySketch(Memory.wrap(bytes.get()));
Assert.assertEquals(sketch.getEstimate(), 0.0);
}
use of com.yahoo.sketches.tuple.ArrayOfDoublesSketch in project sketches-pig by DataSketches.
the class UnionArrayOfDoublesSketchTest method algebraicIntemediateFinalEstimation.
@Test
public void algebraicIntemediateFinalEstimation() throws Exception {
EvalFunc<Tuple> func = new UnionArrayOfDoublesSketch.IntermediateFinal("16384", "1");
DataBag bag = BagFactory.getInstance().newDefaultBag();
long value = 1;
// this is to simulate the output from Initial
{
ArrayOfDoublesUpdatableSketch sketch = new ArrayOfDoublesUpdatableSketchBuilder().setNominalEntries(16384).build();
for (int i = 0; i < 20000; i++) sketch.update(value++, new double[] { 1.0 });
DataBag innerBag = PigUtil.tuplesToBag(PigUtil.objectsToTuple(new DataByteArray(sketch.compact().toByteArray())));
bag.add(PigUtil.objectsToTuple(innerBag));
}
// this is to simulate the output from a prior call of IntermediateFinal
{
ArrayOfDoublesUpdatableSketch sketch = new ArrayOfDoublesUpdatableSketchBuilder().setNominalEntries(16384).build();
for (int i = 0; i < 20000; i++) sketch.update(value++, new double[] { 1.0 });
bag.add(PigUtil.objectsToTuple(new DataByteArray(sketch.compact().toByteArray())));
}
Tuple resultTuple = func.exec(PigUtil.objectsToTuple(bag));
Assert.assertNotNull(resultTuple);
Assert.assertEquals(resultTuple.size(), 1);
DataByteArray bytes = (DataByteArray) resultTuple.get(0);
Assert.assertTrue(bytes.size() > 0);
ArrayOfDoublesSketch sketch = ArrayOfDoublesSketches.heapifySketch(Memory.wrap(bytes.get()));
Assert.assertEquals(sketch.getEstimate(), 40000.0, 40000.0 * 0.01);
for (double[] values : sketch.getValues()) {
Assert.assertEquals(values[0], 1.0, 0.0);
}
}
use of com.yahoo.sketches.tuple.ArrayOfDoublesSketch in project sketches-pig by DataSketches.
the class UnionArrayOfDoublesSketchTest method accumulatorNullInput.
@Test
public void accumulatorNullInput() throws Exception {
Accumulator<Tuple> func = new UnionArrayOfDoublesSketch();
func.accumulate(null);
Tuple resultTuple = func.getValue();
Assert.assertNotNull(resultTuple);
Assert.assertEquals(resultTuple.size(), 1);
DataByteArray bytes = (DataByteArray) resultTuple.get(0);
Assert.assertTrue(bytes.size() > 0);
ArrayOfDoublesSketch sketch = ArrayOfDoublesSketches.heapifySketch(Memory.wrap(bytes.get()));
Assert.assertEquals(sketch.getEstimate(), 0.0);
}
use of com.yahoo.sketches.tuple.ArrayOfDoublesSketch in project sketches-pig by DataSketches.
the class UnionArrayOfDoublesSketchTest method accumulatorEmptyInnerTuple.
@Test
public void accumulatorEmptyInnerTuple() throws Exception {
Accumulator<Tuple> func = new UnionArrayOfDoublesSketch();
func.accumulate(PigUtil.objectsToTuple(PigUtil.tuplesToBag(TupleFactory.getInstance().newTuple())));
Tuple resultTuple = func.getValue();
Assert.assertNotNull(resultTuple);
Assert.assertEquals(resultTuple.size(), 1);
DataByteArray bytes = (DataByteArray) resultTuple.get(0);
Assert.assertTrue(bytes.size() > 0);
ArrayOfDoublesSketch sketch = ArrayOfDoublesSketches.heapifySketch(Memory.wrap(bytes.get()));
Assert.assertEquals(sketch.getEstimate(), 0.0);
}
Aggregations