use of com.yahoo.sketches.tuple.DoubleSummaryDeserializer in project sketches-pig by DataSketches.
the class DataToDoubleSummarySketchTest method execAllInputTypes.
@Test
public void execAllInputTypes() throws Exception {
EvalFunc<Tuple> func = new DataToDoubleSummarySketch();
DataBag bag = BagFactory.getInstance().newDefaultBag();
bag.add(PigUtil.objectsToTuple("a", 1.0));
bag.add(PigUtil.objectsToTuple("b", 1.0));
bag.add(PigUtil.objectsToTuple("a", 2.0));
bag.add(PigUtil.objectsToTuple("b", 2.0));
bag.add(PigUtil.objectsToTuple(1, 3.0));
bag.add(PigUtil.objectsToTuple(2L, 3.0));
bag.add(PigUtil.objectsToTuple(1f, 3.0));
bag.add(PigUtil.objectsToTuple(2.0, 3.0));
bag.add(PigUtil.objectsToTuple((byte) 3, 3.0));
bag.add(PigUtil.objectsToTuple(new DataByteArray("c".getBytes()), 3.0));
Tuple inputTuple = PigUtil.objectsToTuple(bag);
Tuple resultTuple = func.exec(inputTuple);
Assert.assertNotNull(resultTuple);
Assert.assertEquals(resultTuple.size(), 1);
DataByteArray bytes = (DataByteArray) resultTuple.get(0);
Assert.assertTrue(bytes.size() > 0);
Sketch<DoubleSummary> sketch = Sketches.heapifySketch(Memory.wrap(bytes.get()), new DoubleSummaryDeserializer());
Assert.assertEquals(sketch.getEstimate(), 8.0, 0.0);
SketchIterator<DoubleSummary> it = sketch.iterator();
while (it.next()) {
Assert.assertEquals(it.getSummary().getValue(), 3.0);
}
}
use of com.yahoo.sketches.tuple.DoubleSummaryDeserializer in project sketches-pig by DataSketches.
the class DataToDoubleSummarySketchTest method execEmptyBag.
@Test
public void execEmptyBag() throws Exception {
EvalFunc<Tuple> func = new DataToDoubleSummarySketch();
Tuple inputTuple = PigUtil.objectsToTuple(BagFactory.getInstance().newDefaultBag());
Tuple resultTuple = func.exec(inputTuple);
Assert.assertNotNull(resultTuple);
Assert.assertEquals(resultTuple.size(), 1);
DataByteArray bytes = (DataByteArray) resultTuple.get(0);
Assert.assertTrue(bytes.size() > 0);
Sketch<DoubleSummary> sketch = Sketches.heapifySketch(Memory.wrap(bytes.get()), new DoubleSummaryDeserializer());
Assert.assertEquals(sketch.getEstimate(), 0.0);
}
use of com.yahoo.sketches.tuple.DoubleSummaryDeserializer in project sketches-pig by DataSketches.
the class UnionDoubleSummarySketchTest method exec.
@Test
public void exec() throws Exception {
EvalFunc<Tuple> func = new UnionDoubleSummarySketch("4096");
DataBag bag = BagFactory.getInstance().newDefaultBag();
{
UpdatableSketch<Double, DoubleSummary> sketch = new UpdatableSketchBuilder<Double, DoubleSummary>(new DoubleSummaryFactory()).build();
sketch.update(1, 1.0);
sketch.update(2, 1.0);
bag.add(PigUtil.objectsToTuple(new DataByteArray(sketch.compact().toByteArray())));
}
{
UpdatableSketch<Double, DoubleSummary> sketch = new UpdatableSketchBuilder<Double, DoubleSummary>(new DoubleSummaryFactory()).build();
sketch.update(1, 1.0);
sketch.update(2, 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);
Sketch<DoubleSummary> sketch = Sketches.heapifySketch(Memory.wrap(bytes.get()), new DoubleSummaryDeserializer());
Assert.assertEquals(sketch.getEstimate(), 2.0, 0.0);
SketchIterator<DoubleSummary> it = sketch.iterator();
while (it.next()) {
Assert.assertEquals(it.getSummary().getValue(), 2.0, 0.0);
}
}
use of com.yahoo.sketches.tuple.DoubleSummaryDeserializer in project sketches-pig by DataSketches.
the class UnionDoubleSummarySketchTest method execMaxMode.
@Test
public void execMaxMode() throws Exception {
EvalFunc<Tuple> func = new UnionDoubleSummarySketch("4096", "Max");
DataBag bag = BagFactory.getInstance().newDefaultBag();
{
UpdatableSketch<Double, DoubleSummary> sketch = new UpdatableSketchBuilder<Double, DoubleSummary>(new DoubleSummaryFactory()).build();
sketch.update(1, 1.0);
sketch.update(2, 1.0);
bag.add(PigUtil.objectsToTuple(new DataByteArray(sketch.compact().toByteArray())));
}
{
UpdatableSketch<Double, DoubleSummary> sketch = new UpdatableSketchBuilder<Double, DoubleSummary>(new DoubleSummaryFactory()).build();
sketch.update(1, 3.0);
sketch.update(2, 3.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);
Sketch<DoubleSummary> sketch = Sketches.heapifySketch(Memory.wrap(bytes.get()), new DoubleSummaryDeserializer());
Assert.assertEquals(sketch.getEstimate(), 2.0, 0.0);
SketchIterator<DoubleSummary> it = sketch.iterator();
while (it.next()) {
Assert.assertEquals(it.getSummary().getValue(), 3.0, 0.0);
}
}
use of com.yahoo.sketches.tuple.DoubleSummaryDeserializer in project sketches-pig by DataSketches.
the class UnionDoubleSummarySketchTest method accumulatorEmptyBag.
@Test
public void accumulatorEmptyBag() throws Exception {
Accumulator<Tuple> func = new UnionDoubleSummarySketch("32");
func.accumulate(PigUtil.objectsToTuple(BagFactory.getInstance().newDefaultBag()));
Tuple resultTuple = func.getValue();
Assert.assertNotNull(resultTuple);
Assert.assertEquals(resultTuple.size(), 1);
DataByteArray bytes = (DataByteArray) resultTuple.get(0);
Assert.assertTrue(bytes.size() > 0);
Sketch<DoubleSummary> sketch = Sketches.heapifySketch(Memory.wrap(bytes.get()), new DoubleSummaryDeserializer());
Assert.assertEquals(sketch.getEstimate(), 0.0);
}
Aggregations