Search in sources :

Example 6 with Union

use of com.yahoo.sketches.pig.theta.Union 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 7 with Union

use of com.yahoo.sketches.pig.theta.Union 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)

Example 8 with Union

use of com.yahoo.sketches.pig.theta.Union 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 9 with Union

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

the class UnionTest method checkBadClassCast.

@Test(expectedExceptions = ClassCastException.class)
public void checkBadClassCast() throws IOException {
    Accumulator<Tuple> unionFunc = new Union("256");
    // valid size, but null
    Tuple inputTuple = TupleFactory.getInstance().newTuple(1);
    // wrong type. Cannot Union datums.
    inputTuple.set(0, new Double(1.0));
    // throws ClassCastException
    unionFunc.accumulate(inputTuple);
}
Also used : Tuple(org.apache.pig.data.Tuple) Union(com.yahoo.sketches.pig.theta.Union) Test(org.testng.annotations.Test)

Aggregations

Union (com.yahoo.sketches.pig.theta.Union)9 Test (org.testng.annotations.Test)9 Tuple (org.apache.pig.data.Tuple)8 Estimate (com.yahoo.sketches.pig.theta.Estimate)5 DataBag (org.apache.pig.data.DataBag)4 DataByteArray (org.apache.pig.data.DataByteArray)2 Schema (org.apache.pig.impl.logicalLayer.schema.Schema)1