Search in sources :

Example 1 with Estimate

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

the class IntersectTest method checkAlgFinalFromPriorIntermed.

@Test
public void checkAlgFinalFromPriorIntermed() throws IOException {
    EvalFunc<Tuple> interFuncIFinal = new Intersect.IntermediateFinal();
    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(256, i * 64, 256));
        bag.add(sketchTuple);
    // inputTuple.bag0:sketchTuple0.DBA0
    // inputTuple.bag0:sketchTuple1.DBA1
    // inputTuple.bag0:sketchTuple2.DBA2
    // inputTuple.bag0:sketchTuple3.DBA3
    }
    Tuple resultTuple = interFuncIFinal.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, 64.0, 0.0);
}
Also used : Estimate(com.yahoo.sketches.pig.theta.Estimate) DataBag(org.apache.pig.data.DataBag) DataByteArray(org.apache.pig.data.DataByteArray) Tuple(org.apache.pig.data.Tuple) Test(org.testng.annotations.Test)

Example 2 with Estimate

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

the class IntersectTest method checkAlgFinalInnerNotDBA.

@Test(expectedExceptions = IllegalArgumentException.class)
public void checkAlgFinalInnerNotDBA() 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);
    // 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 3 with Estimate

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

the class IntersectTest method checkNullInput.

@Test
public void checkNullInput() throws IOException {
    EvalFunc<Tuple> interFunc = new Intersect();
    EvalFunc<Double> estFunc = new Estimate();
    Tuple inputTuple = TupleFactory.getInstance().newTuple(1);
    // null bag
    Tuple resultTuple = interFunc.exec(inputTuple);
    assertNotNull(resultTuple);
    assertEquals(resultTuple.size(), 1);
    Double est = estFunc.exec(resultTuple);
    assertEquals(est, 0.0, 0.0);
}
Also used : Intersect(com.yahoo.sketches.pig.theta.Intersect) Estimate(com.yahoo.sketches.pig.theta.Estimate) Tuple(org.apache.pig.data.Tuple) Test(org.testng.annotations.Test)

Example 4 with Estimate

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

the class IntersectTest method checkAlgFinalOuterBagEmptyTuples.

@Test(expectedExceptions = SketchesStateException.class)
public void checkAlgFinalOuterBagEmptyTuples() 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);
    // Throws Illegal Result from HeapIntersection
    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 5 with Estimate

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

the class IntersectTest method checkAlgFinalFromPriorInitial.

@Test
public void checkAlgFinalFromPriorInitial() throws IOException {
    EvalFunc<Tuple> interFuncFinal = new Intersect.IntermediateFinal();
    EvalFunc<Double> estFunc = new Estimate();
    Tuple inputTuple = TupleFactory.getInstance().newTuple(1);
    DataBag bag = BagFactory.getInstance().newDefaultBag();
    // inputTuple.bag0:null
    inputTuple.set(0, bag);
    Tuple innerTuple = TupleFactory.getInstance().newTuple(1);
    DataBag innerBag = BagFactory.getInstance().newDefaultBag();
    // innerTuple.innerBag0:null
    innerTuple.set(0, innerBag);
    // inputTuple.bag0.innerTuple0.innerBag0:null
    bag.add(innerTuple);
    for (int i = 0; i < 4; i++) {
        Tuple sketchTuple = TupleFactory.getInstance().newTuple(1);
        sketchTuple.set(0, createDbaFromQssRange(256, i * 64, 256));
        innerBag.add(sketchTuple);
    // inputTuple.bag0.innerTuple0.innerBag0.sketchTuple0.DBA0
    // inputTuple.bag0.innerTuple0.innerBag0.sketchTuple1.DBA1
    // inputTuple.bag0.innerTuple0.innerBag0.sketchTuple2.DBA2
    // inputTuple.bag0.innerTuple0.innerBag0.sketchTuple3.DBA3
    }
    Tuple resultTuple = interFuncFinal.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, 64.0, 0.0);
}
Also used : Estimate(com.yahoo.sketches.pig.theta.Estimate) DataBag(org.apache.pig.data.DataBag) DataByteArray(org.apache.pig.data.DataByteArray) 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