use of com.yahoo.sketches.hll.HllSketch in project sketches-pig by DataSketches.
the class SketchToStringTest method normalCase.
@Test
public void normalCase() throws Exception {
EvalFunc<String> func = new SketchToString();
HllSketch sketch = new HllSketch(12);
String result = func.exec(tupleFactory.newTuple(new DataByteArray(sketch.toCompactByteArray())));
Assert.assertNotNull(result);
Assert.assertTrue(result.length() > 0);
}
use of com.yahoo.sketches.hll.HllSketch in project sketches-pig by DataSketches.
the class UnionSketchTest method algebraicFinalEmptyInputTuple.
@Test
public void algebraicFinalEmptyInputTuple() throws Exception {
@SuppressWarnings("unchecked") EvalFunc<DataByteArray> func = (EvalFunc<DataByteArray>) Class.forName(new UnionSketch().getFinal()).getConstructor(String.class).newInstance("10");
DataByteArray result = func.exec(tupleFactory.newTuple());
HllSketch sketch = DataToSketchTest.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 UnionSketchTest method execEmptyInputTuple.
@Test
public void execEmptyInputTuple() throws Exception {
EvalFunc<DataByteArray> func = new UnionSketch("10");
DataByteArray result = func.exec(tupleFactory.newTuple());
HllSketch sketch = DataToSketchTest.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 UnionSketchTest method execNormalCase.
@Test
public void execNormalCase() throws Exception {
EvalFunc<DataByteArray> func = new UnionSketch();
HllSketch inputSketch = new HllSketch(12);
inputSketch.update(1);
inputSketch.update(2);
DataBag bag = bagFactory.newDefaultBag();
bag.add(tupleFactory.newTuple(new DataByteArray(inputSketch.toCompactByteArray())));
DataByteArray result = func.exec(tupleFactory.newTuple(bag));
HllSketch sketch = DataToSketchTest.getSketch(result);
Assert.assertFalse(sketch.isEmpty());
Assert.assertEquals(sketch.getEstimate(), 2.0, 0.01);
}
use of com.yahoo.sketches.hll.HllSketch in project sketches-pig by DataSketches.
the class UnionSketchTest method accumulator.
@Test
public void accumulator() throws Exception {
Accumulator<DataByteArray> func = new UnionSketch();
// no input yet
DataByteArray result = func.getValue();
HllSketch sketch = DataToSketchTest.getSketch(result);
Assert.assertTrue(sketch.isEmpty());
// null input tuple
func.accumulate(null);
result = func.getValue();
sketch = DataToSketchTest.getSketch(result);
Assert.assertTrue(sketch.isEmpty());
// empty input tuple
func.accumulate(tupleFactory.newTuple());
result = func.getValue();
sketch = DataToSketchTest.getSketch(result);
Assert.assertTrue(sketch.isEmpty());
// empty bag
func.accumulate(tupleFactory.newTuple(bagFactory.newDefaultBag()));
result = func.getValue();
sketch = DataToSketchTest.getSketch(result);
Assert.assertTrue(sketch.isEmpty());
// normal case
HllSketch inputSketch = new HllSketch(12);
inputSketch.update(1);
inputSketch.update(2);
DataBag bag = bagFactory.newDefaultBag();
bag.add(tupleFactory.newTuple(new DataByteArray(inputSketch.toCompactByteArray())));
func.accumulate(tupleFactory.newTuple(bag));
result = func.getValue();
sketch = DataToSketchTest.getSketch(result);
Assert.assertFalse(sketch.isEmpty());
Assert.assertEquals(sketch.getEstimate(), 2.0, 0.01);
// cleanup
func.cleanup();
result = func.getValue();
sketch = DataToSketchTest.getSketch(result);
Assert.assertTrue(sketch.isEmpty());
}
Aggregations