use of com.yahoo.sketches.quantiles.ItemsSketch in project sketches-pig by DataSketches.
the class DataToStringsSketchTest method algebraicIntermediateFinalNormalCase.
@Test
public void algebraicIntermediateFinalNormalCase() throws Exception {
@SuppressWarnings("unchecked") EvalFunc<Tuple> func = (EvalFunc<Tuple>) Class.forName(new DataToStringsSketch().getIntermed()).newInstance();
DataBag bag = BAG_FACTORY.newDefaultBag();
{
// this is to simulate an output from Initial
DataBag innerBag = BAG_FACTORY.newDefaultBag();
innerBag.add(TUPLE_FACTORY.newTuple("a"));
bag.add(TUPLE_FACTORY.newTuple(innerBag));
}
{
// this is to simulate an output from a prior call of IntermediateFinal
ItemsSketch<String> qs = ItemsSketch.getInstance(COMPARATOR);
qs.update("b");
bag.add(TUPLE_FACTORY.newTuple(new DataByteArray(qs.toByteArray(SER_DE))));
}
Tuple resultTuple = func.exec(TUPLE_FACTORY.newTuple(bag));
ItemsSketch<String> sketch = getSketch(resultTuple);
Assert.assertFalse(sketch.isEmpty());
Assert.assertEquals(sketch.getN(), 2);
}
use of com.yahoo.sketches.quantiles.ItemsSketch in project sketches-pig by DataSketches.
the class UnionStringsSketchTest method algebraicIntermediateFinalNormalCase.
@Test
public void algebraicIntermediateFinalNormalCase() throws Exception {
@SuppressWarnings("unchecked") EvalFunc<Tuple> func = (EvalFunc<Tuple>) Class.forName(new UnionStringsSketch().getIntermed()).newInstance();
DataBag bag = BAG_FACTORY.newDefaultBag();
{
// this is to simulate an output from Initial
DataBag innerBag = BAG_FACTORY.newDefaultBag();
ItemsSketch<String> qs = ItemsSketch.getInstance(COMPARATOR);
qs.update("a");
innerBag.add(TUPLE_FACTORY.newTuple(new DataByteArray(qs.toByteArray(SER_DE))));
bag.add(TUPLE_FACTORY.newTuple(innerBag));
}
{
// this is to simulate an output from a prior call of IntermediateFinal
ItemsSketch<String> qs = ItemsSketch.getInstance(COMPARATOR);
qs.update("b");
bag.add(TUPLE_FACTORY.newTuple(new DataByteArray(qs.toByteArray(SER_DE))));
}
Tuple resultTuple = func.exec(TUPLE_FACTORY.newTuple(bag));
ItemsSketch<String> sketch = getSketch(resultTuple);
Assert.assertFalse(sketch.isEmpty());
Assert.assertEquals(sketch.getN(), 2);
}
Aggregations