use of com.yahoo.sketches.hll.HllSketch in project sketches-pig by DataSketches.
the class DataToSketchTest method algebraicIntermediateFromInitial.
@Test
public void algebraicIntermediateFromInitial() throws Exception {
@SuppressWarnings("unchecked") EvalFunc<Tuple> func = (EvalFunc<Tuple>) Class.forName(new DataToSketch().getIntermed()).newInstance();
DataBag outerBag = bagFactory.newDefaultBag();
DataBag innerBag = bagFactory.newDefaultBag();
innerBag.add(tupleFactory.newTuple("a"));
innerBag.add(tupleFactory.newTuple("b"));
innerBag.add(tupleFactory.newTuple("c"));
outerBag.add(tupleFactory.newTuple(innerBag));
Tuple result = func.exec(tupleFactory.newTuple(outerBag));
HllSketch sketch = getSketch((DataByteArray) result.get(0));
Assert.assertFalse(sketch.isEmpty());
Assert.assertEquals(sketch.getEstimate(), 3.0, 0.01);
}
use of com.yahoo.sketches.hll.HllSketch in project sketches-pig by DataSketches.
the class DataToSketchTest method algebraicFinalEmptyInputTuple.
@Test
public void algebraicFinalEmptyInputTuple() throws Exception {
@SuppressWarnings("unchecked") EvalFunc<DataByteArray> func = (EvalFunc<DataByteArray>) Class.forName(new DataToSketch().getFinal()).getConstructor(String.class).newInstance("10");
DataByteArray result = func.exec(tupleFactory.newTuple());
HllSketch sketch = getSketch(result);
Assert.assertTrue(sketch.isEmpty());
Assert.assertEquals(sketch.getLgConfigK(), 10);
}
use of com.yahoo.sketches.hll.HllSketch in project sketches-pig by DataSketches.
the class DataToSketchTest method accumulator.
@Test
public void accumulator() throws Exception {
Accumulator<DataByteArray> func = new DataToSketch();
// no input yet
DataByteArray result = func.getValue();
HllSketch sketch = getSketch(result);
Assert.assertTrue(sketch.isEmpty());
// null input tuple
func.accumulate(null);
result = func.getValue();
sketch = getSketch(result);
Assert.assertTrue(sketch.isEmpty());
// empty input tuple
func.accumulate(tupleFactory.newTuple());
result = func.getValue();
sketch = getSketch(result);
Assert.assertTrue(sketch.isEmpty());
// empty bag
func.accumulate(tupleFactory.newTuple(bagFactory.newDefaultBag()));
result = func.getValue();
sketch = getSketch(result);
Assert.assertTrue(sketch.isEmpty());
// normal case
DataBag bag = bagFactory.newDefaultBag();
bag.add(tupleFactory.newTuple("a"));
bag.add(tupleFactory.newTuple("b"));
func.accumulate(tupleFactory.newTuple(bag));
result = func.getValue();
sketch = getSketch(result);
Assert.assertFalse(sketch.isEmpty());
Assert.assertEquals(sketch.getEstimate(), 2.0, 0.01);
// cleanup
func.cleanup();
result = func.getValue();
sketch = getSketch(result);
Assert.assertTrue(sketch.isEmpty());
}
use of com.yahoo.sketches.hll.HllSketch in project sketches-pig by DataSketches.
the class SketchToEstimateAndErrorBoundsTest method normalCase.
@Test
public void normalCase() throws Exception {
EvalFunc<Tuple> func = new SketchToEstimateAndErrorBounds();
HllSketch sketch = new HllSketch(12);
sketch.update(1);
sketch.update(2);
Tuple result = func.exec(tupleFactory.newTuple(new DataByteArray(sketch.toCompactByteArray())));
Assert.assertNotNull(result);
Assert.assertEquals((Double) result.get(0), 2.0, 0.01);
Assert.assertTrue((Double) result.get(1) <= 2.0);
Assert.assertTrue((Double) result.get(2) >= 2.0);
}
use of com.yahoo.sketches.hll.HllSketch in project sketches-pig by DataSketches.
the class SketchToEstimateTest method normalCase.
@Test
public void normalCase() throws Exception {
EvalFunc<Double> func = new SketchToEstimate();
HllSketch sketch = new HllSketch(12);
sketch.update(1);
sketch.update(2);
Double result = func.exec(tupleFactory.newTuple(new DataByteArray(sketch.toCompactByteArray())));
Assert.assertNotNull(result);
Assert.assertEquals(result, 2.0, 0.01);
}
Aggregations