use of com.yahoo.sketches.pig.theta.Estimate in project sketches-pig by DataSketches.
the class IntersectTest method checkAlgFinalInnerBagEmpty.
@Test(expectedExceptions = SketchesStateException.class)
public void checkAlgFinalInnerBagEmpty() throws IOException {
EvalFunc<Tuple> interFuncFinal = new Intersect.IntermediateFinal();
EvalFunc<Double> estFunc = new Estimate();
Tuple inputTuple = TupleFactory.getInstance().newTuple(1);
Tuple resultTuple = interFuncFinal.exec(inputTuple);
assertEquals(estFunc.exec(resultTuple), 0.0, 0.0);
DataBag bag = BagFactory.getInstance().newDefaultBag();
// inputTuple.bag0:null
inputTuple.set(0, bag);
resultTuple = interFuncFinal.exec(inputTuple);
assertEquals(estFunc.exec(resultTuple), 0.0, 0.0);
Tuple innerTuple = TupleFactory.getInstance().newTuple(1);
bag.add(innerTuple);
DataBag bag2 = BagFactory.getInstance().newDefaultBag();
innerTuple.set(0, bag2);
// Throws Illegal Result from HeapIntersection
resultTuple = interFuncFinal.exec(inputTuple);
// assertEquals(estFunc.exec(resultTuple), 0.0, 0.0);
}
use of com.yahoo.sketches.pig.theta.Estimate in project sketches-pig by DataSketches.
the class UnionTest method checkAlgFinalInnerBagEmpty.
@Test
public void checkAlgFinalInnerBagEmpty() throws IOException {
EvalFunc<Tuple> interFuncFinal = new Union.IntermediateFinal("256");
EvalFunc<Double> estFunc = new Estimate();
Tuple inputTuple = TupleFactory.getInstance().newTuple(1);
Tuple resultTuple = interFuncFinal.exec(inputTuple);
assertEquals(estFunc.exec(resultTuple), 0.0, 0.0);
DataBag bag = BagFactory.getInstance().newDefaultBag();
// inputTuple.bag0:null
inputTuple.set(0, bag);
resultTuple = interFuncFinal.exec(inputTuple);
assertEquals(estFunc.exec(resultTuple), 0.0, 0.0);
Tuple innerTuple = TupleFactory.getInstance().newTuple(1);
bag.add(innerTuple);
DataBag bag2 = BagFactory.getInstance().newDefaultBag();
innerTuple.set(0, bag2);
resultTuple = interFuncFinal.exec(inputTuple);
assertEquals(estFunc.exec(resultTuple), 0.0, 0.0);
}
use of com.yahoo.sketches.pig.theta.Estimate in project sketches-pig by DataSketches.
the class UnionTest method checkNullEmptyAccumulator.
@Test
public void checkNullEmptyAccumulator() throws IOException {
Accumulator<Tuple> unionFunc = new Union("256");
EvalFunc<Double> estFunc = new Estimate();
Tuple inputTuple = null;
// does nothing, just returns
unionFunc.accumulate(inputTuple);
// invalid size
inputTuple = TupleFactory.getInstance().newTuple(0);
// does nothing, just returns
unionFunc.accumulate(inputTuple);
// valid size, but null
inputTuple = TupleFactory.getInstance().newTuple(1);
// does nothing, just returns
unionFunc.accumulate(inputTuple);
// valid size
inputTuple = TupleFactory.getInstance().newTuple(1);
DataBag bag = BagFactory.getInstance().newDefaultBag();
// correct type, but empty
inputTuple.set(0, bag);
// does nothing, just returns
unionFunc.accumulate(inputTuple);
// empty
Tuple innerTuple = TupleFactory.getInstance().newTuple(0);
bag.add(innerTuple);
// does nothing, just returns
unionFunc.accumulate(inputTuple);
// valid size
inputTuple = TupleFactory.getInstance().newTuple(1);
bag = BagFactory.getInstance().newDefaultBag();
// correct type
inputTuple.set(0, bag);
// correct size
innerTuple = TupleFactory.getInstance().newTuple(1);
// but innerTuple(0) is null
bag.add(innerTuple);
// ignores
unionFunc.accumulate(inputTuple);
Tuple resultTuple = unionFunc.getValue();
assertNotNull(resultTuple);
assertEquals(resultTuple.size(), 1);
Double est = estFunc.exec(resultTuple);
assertEquals(est, 0.0, 0.0);
}
use of com.yahoo.sketches.pig.theta.Estimate in project sketches-pig by DataSketches.
the class UnionTest method checkExactTopExec.
@Test
public void checkExactTopExec() throws IOException {
// default 4096
EvalFunc<Tuple> unionFunc = new Union();
EvalFunc<Double> estFunc = new Estimate();
// create inputTuple and a bag, add bag to inputTuple
Tuple inputTuple = TupleFactory.getInstance().newTuple(1);
DataBag bag = BagFactory.getInstance().newDefaultBag();
inputTuple.set(0, bag);
// create 4 distinct sketches of 64 in a bag
for (int i = 0; i < 4; i++) {
Tuple dataTuple = TupleFactory.getInstance().newTuple(1);
dataTuple.set(0, createDbaFromQssRange(64, i * 64, 64));
bag.add(dataTuple);
}
Tuple resultTuple = unionFunc.exec(inputTuple);
assertNotNull(resultTuple);
assertEquals(resultTuple.size(), 1);
Double est = estFunc.exec(resultTuple);
assertEquals(est, 256.0, 0.0);
}
use of com.yahoo.sketches.pig.theta.Estimate in project sketches-pig by DataSketches.
the class UnionTest method checkAlgFinalFromPriorIntermed.
@Test
public void checkAlgFinalFromPriorIntermed() throws IOException {
EvalFunc<Tuple> unionFuncIFinal = new Union.IntermediateFinal("256");
EvalFunc<Double> estFunc = new Estimate();
Tuple inputTuple = TupleFactory.getInstance().newTuple(1);
DataBag bag = BagFactory.getInstance().newDefaultBag();
// inputTuple.bag0:null
inputTuple.set(0, bag);
for (int i = 0; i < 4; i++) {
Tuple sketchTuple = TupleFactory.getInstance().newTuple(1);
sketchTuple.set(0, createDbaFromQssRange(64, i * 64, 64));
bag.add(sketchTuple);
// inputTuple.bag0:sketchTuple0.DBA0
// inputTuple.bag0:sketchTuple1.DBA1
// inputTuple.bag0:sketchTuple2.DBA2
// inputTuple.bag0:sketchTuple3.DBA3
}
Tuple resultTuple = unionFuncIFinal.exec(inputTuple);
assertNotNull(resultTuple);
assertEquals(resultTuple.size(), 1);
DataByteArray bytes = (DataByteArray) resultTuple.get(0);
assertTrue(bytes.size() > 0);
Double est = estFunc.exec(resultTuple);
assertEquals(est, 256.0, 0.0);
}
Aggregations