Search in sources :

Example 11 with Estimate

use of com.yahoo.sketches.pig.theta.Estimate in project sketches-pig by DataSketches.

the class AexcludeBTest method checkNullCombinations.

@Test
public void checkNullCombinations() throws IOException {
    EvalFunc<Tuple> aNbFunc = new AexcludeB();
    EvalFunc<Double> estFunc = new Estimate();
    Tuple inputTuple, resultTuple;
    Double est;
    // Two nulls
    inputTuple = TupleFactory.getInstance().newTuple(2);
    resultTuple = aNbFunc.exec(inputTuple);
    assertNotNull(resultTuple);
    assertEquals(resultTuple.size(), 1);
    est = estFunc.exec(resultTuple);
    assertEquals(est, 0.0, 0.0);
    // A is null
    inputTuple = TupleFactory.getInstance().newTuple(2);
    inputTuple.set(1, createDbaFromQssRange(256, 0, 128));
    resultTuple = aNbFunc.exec(inputTuple);
    assertNotNull(resultTuple);
    assertEquals(resultTuple.size(), 1);
    est = estFunc.exec(resultTuple);
    assertEquals(est, 0.0, 0.0);
    // A is valid, B is null
    inputTuple = TupleFactory.getInstance().newTuple(2);
    inputTuple.set(0, createDbaFromQssRange(256, 0, 256));
    resultTuple = aNbFunc.exec(inputTuple);
    assertNotNull(resultTuple);
    assertEquals(resultTuple.size(), 1);
    est = estFunc.exec(resultTuple);
    assertEquals(est, 256.0, 0.0);
    // Both valid
    inputTuple = TupleFactory.getInstance().newTuple(2);
    inputTuple.set(0, createDbaFromQssRange(256, 0, 256));
    inputTuple.set(1, createDbaFromQssRange(256, 0, 128));
    resultTuple = aNbFunc.exec(inputTuple);
    assertNotNull(resultTuple);
    assertEquals(resultTuple.size(), 1);
    est = estFunc.exec(resultTuple);
    assertEquals(est, 128.0, 0.0);
}
Also used : AexcludeB(com.yahoo.sketches.pig.theta.AexcludeB) Estimate(com.yahoo.sketches.pig.theta.Estimate) Tuple(org.apache.pig.data.Tuple) Test(org.testng.annotations.Test)

Example 12 with Estimate

use of com.yahoo.sketches.pig.theta.Estimate in project sketches-pig by DataSketches.

the class DataToSketchTest method checkAlgFinalOuterBagEmptyTuples.

@Test
public void checkAlgFinalOuterBagEmptyTuples() throws IOException {
    EvalFunc<Tuple> interFuncFinal = new DataToSketch.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);
    resultTuple = interFuncFinal.exec(inputTuple);
    assertEquals(estFunc.exec(resultTuple), 0.0, 0.0);
}
Also used : Estimate(com.yahoo.sketches.pig.theta.Estimate) DataBag(org.apache.pig.data.DataBag) Tuple(org.apache.pig.data.Tuple) Test(org.testng.annotations.Test)

Example 13 with Estimate

use of com.yahoo.sketches.pig.theta.Estimate in project sketches-pig by DataSketches.

the class DataToSketchTest method checkAlgFinalInnerNotDBA.

@Test(expectedExceptions = IllegalArgumentException.class)
public void checkAlgFinalInnerNotDBA() throws IOException {
    EvalFunc<Tuple> interFuncFinal = new DataToSketch.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);
    // not a DBA
    innerTuple.set(0, new Double(1.0));
    resultTuple = interFuncFinal.exec(inputTuple);
    assertEquals(estFunc.exec(resultTuple), 0.0, 0.0);
}
Also used : Estimate(com.yahoo.sketches.pig.theta.Estimate) DataBag(org.apache.pig.data.DataBag) Tuple(org.apache.pig.data.Tuple) Test(org.testng.annotations.Test)

Example 14 with Estimate

use of com.yahoo.sketches.pig.theta.Estimate in project sketches-pig by DataSketches.

the class EstimateTest method testExactWithSeed.

@Test
public void testExactWithSeed() throws IOException {
    EvalFunc<Double> func = new Estimate(Long.toString(DEFAULT_UPDATE_SEED));
    Tuple dataTuple = TupleFactory.getInstance().newTuple(1);
    dataTuple.set(0, createDbaFromQssRange(64, 0, 64));
    Double result = func.exec(dataTuple);
    assertNotNull(result);
    assertEquals(result, 64.0, 0.0);
}
Also used : Estimate(com.yahoo.sketches.pig.theta.Estimate) Tuple(org.apache.pig.data.Tuple) Test(org.testng.annotations.Test)

Example 15 with Estimate

use of com.yahoo.sketches.pig.theta.Estimate in project sketches-pig by DataSketches.

the class IntersectTest method checkExactTopExec.

@Test
public void checkExactTopExec() throws IOException {
    EvalFunc<Tuple> interFunc = new Intersect();
    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 overlapping sketches of 64 in a bag
    for (int i = 0; i < 4; i++) {
        Tuple dataTuple = TupleFactory.getInstance().newTuple(1);
        dataTuple.set(0, createDbaFromQssRange(256, i * 64, 256));
        bag.add(dataTuple);
    }
    Tuple resultTuple = interFunc.exec(inputTuple);
    assertNotNull(resultTuple);
    assertEquals(resultTuple.size(), 1);
    Double est = estFunc.exec(resultTuple);
    assertEquals(est, 64.0, 0.0);
}
Also used : Intersect(com.yahoo.sketches.pig.theta.Intersect) Estimate(com.yahoo.sketches.pig.theta.Estimate) DataBag(org.apache.pig.data.DataBag) Tuple(org.apache.pig.data.Tuple) Test(org.testng.annotations.Test)

Aggregations

Estimate (com.yahoo.sketches.pig.theta.Estimate)26 Tuple (org.apache.pig.data.Tuple)26 Test (org.testng.annotations.Test)26 DataBag (org.apache.pig.data.DataBag)19 DataByteArray (org.apache.pig.data.DataByteArray)7 Union (com.yahoo.sketches.pig.theta.Union)5 Intersect (com.yahoo.sketches.pig.theta.Intersect)4 AexcludeB (com.yahoo.sketches.pig.theta.AexcludeB)1