Search in sources :

Example 16 with Estimate

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

the class IntersectTest method checkExactAccumulator.

@Test
public void checkExactAccumulator() throws IOException {
    Accumulator<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 distinct sketches of 32 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);
    }
    // A tuple, bag with 4 sketches
    interFunc.accumulate(inputTuple);
    Tuple resultTuple = interFunc.getValue();
    assertNotNull(resultTuple);
    assertEquals(resultTuple.size(), 1);
    DataByteArray dba = (DataByteArray) resultTuple.get(0);
    assertTrue(dba.size() > 0);
    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) DataByteArray(org.apache.pig.data.DataByteArray) Tuple(org.apache.pig.data.Tuple) Test(org.testng.annotations.Test)

Example 17 with Estimate

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

the class IntersectTest method checkNullEmptyAccumulator.

@Test
public void checkNullEmptyAccumulator() throws IOException {
    Accumulator<Tuple> interFunc = new Intersect();
    EvalFunc<Double> estFunc = new Estimate();
    Tuple inputTuple = null;
    // does nothing
    interFunc.accumulate(inputTuple);
    // invalid size
    inputTuple = TupleFactory.getInstance().newTuple(0);
    // does nothing
    interFunc.accumulate(inputTuple);
    // valid size, but null bag
    inputTuple = TupleFactory.getInstance().newTuple(1);
    // does nothing
    interFunc.accumulate(inputTuple);
    // valid size
    inputTuple = TupleFactory.getInstance().newTuple(1);
    DataBag bag = BagFactory.getInstance().newDefaultBag();
    // correct type, but empty
    inputTuple.set(0, bag);
    // does nothing
    interFunc.accumulate(inputTuple);
    // empty
    Tuple innerTuple = TupleFactory.getInstance().newTuple(0);
    bag.add(innerTuple);
    // does nothing
    interFunc.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);
    // does nothing
    interFunc.accumulate(inputTuple);
    // Must call accumulate at least once before calling getValue.
    // To prove that all the above stuff truely did nothing,
    // we call accumulate once with a valid sketch and affirm that
    // getValue() returns it unaltered.
    // create inputTuple and a bag, add bag to inputTuple
    // valid size
    inputTuple = TupleFactory.getInstance().newTuple(1);
    bag = BagFactory.getInstance().newDefaultBag();
    inputTuple.set(0, bag);
    Tuple dataTuple = TupleFactory.getInstance().newTuple(1);
    dataTuple.set(0, createDbaFromQssRange(256, 0, 64));
    bag.add(dataTuple);
    interFunc.accumulate(inputTuple);
    Tuple resultTuple = interFunc.getValue();
    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)

Example 18 with Estimate

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

the class UnionTest method checkExactAccumulator.

@Test
public void checkExactAccumulator() throws IOException {
    Accumulator<Tuple> unionFunc = new Union("256");
    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 32 in a bag
    for (int i = 0; i < 4; i++) {
        Tuple dataTuple = TupleFactory.getInstance().newTuple(1);
        dataTuple.set(0, createDbaFromQssRange(256, i * 64, 64));
        bag.add(dataTuple);
    }
    // A tuple, bag with 4 sketches
    unionFunc.accumulate(inputTuple);
    Tuple resultTuple = unionFunc.getValue();
    assertNotNull(resultTuple);
    assertEquals(resultTuple.size(), 1);
    DataByteArray dba = (DataByteArray) resultTuple.get(0);
    assertTrue(dba.size() > 0);
    Double est = estFunc.exec(resultTuple);
    assertEquals(est, 256.0, 0.0);
    unionFunc.cleanup();
    resultTuple = unionFunc.getValue();
    assertNotNull(resultTuple);
    assertEquals(resultTuple.size(), 1);
    dba = (DataByteArray) resultTuple.get(0);
    assertTrue(dba.size() > 0);
    est = estFunc.exec(resultTuple);
    assertEquals(est, 0.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) Union(com.yahoo.sketches.pig.theta.Union) Test(org.testng.annotations.Test)

Example 19 with Estimate

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

the class UnionTest method checkAlgFinalInnerNotDBA.

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

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

the class UnionTest method checkEmptyGetValue.

@Test
public void checkEmptyGetValue() throws IOException {
    Accumulator<Tuple> unionFunc = new Union("256");
    EvalFunc<Double> estFunc = new Estimate();
    Tuple resultTuple = unionFunc.getValue();
    DataByteArray dba = (DataByteArray) resultTuple.get(0);
    assertEquals(dba.size(), 8);
    Double est = estFunc.exec(resultTuple);
    assertEquals(est, 0.0, 0.0);
}
Also used : Estimate(com.yahoo.sketches.pig.theta.Estimate) DataByteArray(org.apache.pig.data.DataByteArray) Tuple(org.apache.pig.data.Tuple) Union(com.yahoo.sketches.pig.theta.Union) 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