use of org.apache.pig.EvalFunc in project sketches-pig by DataSketches.
the class UnionSketchTest method algebraicFinalFromIntermediate.
@Test
public void algebraicFinalFromIntermediate() throws Exception {
@SuppressWarnings("unchecked") EvalFunc<DataByteArray> func = (EvalFunc<DataByteArray>) Class.forName(new UnionSketch().getFinal()).newInstance();
HllSketch inputSketch = new HllSketch(12);
inputSketch.update("a");
inputSketch.update("b");
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 org.apache.pig.EvalFunc in project sketches-pig by DataSketches.
the class DataToStringsSketchTest method algebraicInitial.
@Test
public void algebraicInitial() throws Exception {
@SuppressWarnings("unchecked") EvalFunc<Tuple> func = (EvalFunc<Tuple>) Class.forName(new DataToStringsSketch().getInitial()).newInstance();
DataBag bag = BAG_FACTORY.newDefaultBag();
bag.add(TUPLE_FACTORY.newTuple());
Tuple resultTuple = func.exec(TUPLE_FACTORY.newTuple(bag));
Assert.assertNotNull(resultTuple);
Assert.assertEquals(resultTuple.size(), 1);
Assert.assertTrue(resultTuple.get(0) instanceof DataBag);
Assert.assertEquals(((DataBag) resultTuple.get(0)).size(), 1);
}
use of org.apache.pig.EvalFunc 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 org.apache.pig.EvalFunc in project sketches-pig by DataSketches.
the class DataToStringsSketchTest method algebraicIntermediateFinalWrongType.
@Test(expectedExceptions = IllegalArgumentException.class)
public void algebraicIntermediateFinalWrongType() throws Exception {
@SuppressWarnings("unchecked") EvalFunc<Tuple> func = (EvalFunc<Tuple>) Class.forName(new DataToStringsSketch().getIntermed()).newInstance();
DataBag bag = BAG_FACTORY.newDefaultBag();
// this bag must have tuples with either bags or data byte arrays
bag.add(TUPLE_FACTORY.newTuple("a"));
func.exec(TUPLE_FACTORY.newTuple(bag));
}
use of org.apache.pig.EvalFunc 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