Search in sources :

Example 21 with Estimate

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

the class UnionTest method checkNullInput.

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

Example 22 with Estimate

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

the class UnionTest method checkAlgFinalOuterBagEmptyTuples.

@Test
public void checkAlgFinalOuterBagEmptyTuples() 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);
    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 23 with Estimate

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

the class UnionTest method checkAlgFinalFromPriorInitial.

@Test
public void checkAlgFinalFromPriorInitial() throws IOException {
    EvalFunc<Tuple> unionFuncFinal = 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);
    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(64, i * 64, 64));
        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 = unionFuncFinal.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);
}
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 24 with Estimate

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

the class DataToSketchTest method checkAlgFinalInnerBagEmpty.

@Test
public void checkAlgFinalInnerBagEmpty() 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);
    DataBag bag2 = BagFactory.getInstance().newDefaultBag();
    innerTuple.set(0, bag2);
    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 25 with Estimate

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

the class EstimateTest method testExact.

@Test
public void testExact() throws IOException {
    EvalFunc<Double> func = new Estimate();
    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)

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