use of org.apache.pig.data.DataBag in project sketches-pig by DataSketches.
the class UnionSketchTest method algebraicIntermediateFromIntermediate.
@Test
public void algebraicIntermediateFromIntermediate() throws Exception {
@SuppressWarnings("unchecked") EvalFunc<Tuple> func = (EvalFunc<Tuple>) Class.forName(new UnionSketch().getIntermed()).newInstance();
HllSketch inputSketch = new HllSketch(12);
inputSketch.update("a");
inputSketch.update("b");
DataBag bag = bagFactory.newDefaultBag();
bag.add(tupleFactory.newTuple(new DataByteArray(inputSketch.toCompactByteArray())));
Tuple result = func.exec(tupleFactory.newTuple(bag));
HllSketch sketch = DataToSketchTest.getSketch((DataByteArray) result.get(0));
Assert.assertFalse(sketch.isEmpty());
Assert.assertEquals(sketch.getEstimate(), 2.0, 0.01);
}
use of org.apache.pig.data.DataBag in project sketches-pig by DataSketches.
the class UnionSketchTest method algebraicFinalFromInitial.
@Test
public void algebraicFinalFromInitial() throws Exception {
@SuppressWarnings("unchecked") EvalFunc<DataByteArray> func = (EvalFunc<DataByteArray>) Class.forName(new UnionSketch().getFinal()).getConstructor(String.class, String.class).newInstance("10", "HLL_6");
HllSketch inputSketch = new HllSketch(12);
inputSketch.update(1);
inputSketch.update(2);
inputSketch.update(3);
DataBag outerBag = bagFactory.newDefaultBag();
DataBag innerBag = bagFactory.newDefaultBag();
innerBag.add(tupleFactory.newTuple(new DataByteArray(inputSketch.toCompactByteArray())));
outerBag.add(tupleFactory.newTuple(innerBag));
DataByteArray result = func.exec(tupleFactory.newTuple(outerBag));
HllSketch sketch = DataToSketchTest.getSketch(result);
Assert.assertFalse(sketch.isEmpty());
Assert.assertEquals(sketch.getEstimate(), 3.0, 0.01);
Assert.assertEquals(sketch.getLgConfigK(), 10);
Assert.assertEquals(sketch.getTgtHllType(), TgtHllType.HLL_6);
}
use of org.apache.pig.data.DataBag in project sketches-pig by DataSketches.
the class UnionSketchTest method algebraicIntermediateFromInitial.
@Test
public void algebraicIntermediateFromInitial() throws Exception {
@SuppressWarnings("unchecked") EvalFunc<Tuple> func = (EvalFunc<Tuple>) Class.forName(new UnionSketch().getIntermed()).getConstructor(String.class, String.class).newInstance("10", "HLL_6");
HllSketch inputSketch = new HllSketch(12);
inputSketch.update(1);
inputSketch.update(2);
inputSketch.update(3);
DataBag outerBag = bagFactory.newDefaultBag();
DataBag innerBag = bagFactory.newDefaultBag();
innerBag.add(tupleFactory.newTuple(new DataByteArray(inputSketch.toCompactByteArray())));
outerBag.add(tupleFactory.newTuple(innerBag));
Tuple result = func.exec(tupleFactory.newTuple(outerBag));
HllSketch sketch = DataToSketchTest.getSketch((DataByteArray) result.get(0));
Assert.assertFalse(sketch.isEmpty());
Assert.assertEquals(sketch.getEstimate(), 3.0, 0.01);
Assert.assertEquals(sketch.getLgConfigK(), 10);
Assert.assertEquals(sketch.getTgtHllType(), TgtHllType.HLL_6);
}
use of org.apache.pig.data.DataBag in project sketches-pig by DataSketches.
the class DataToDoublesSketchTest method algebraicInitial.
@Test
public void algebraicInitial() throws Exception {
EvalFunc<Tuple> func = new DataToDoublesSketch.Initial();
DataBag bag = bagFactory.newDefaultBag();
bag.add(tupleFactory.newTuple());
Tuple resultTuple = func.exec(tupleFactory.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.data.DataBag in project sketches-pig by DataSketches.
the class DataToDoublesSketchTest method algebraicIntermediateFinalWrongType.
@Test(expectedExceptions = IllegalArgumentException.class)
public void algebraicIntermediateFinalWrongType() throws Exception {
EvalFunc<Tuple> func = new DataToDoublesSketch.IntermediateFinal();
DataBag bag = bagFactory.newDefaultBag();
// this bag must have tuples with either bags or data byte arrays
bag.add(tupleFactory.newTuple(1.0));
func.exec(tupleFactory.newTuple(bag));
}
Aggregations