Search in sources :

Example 1 with DoubleSummaryFactory

use of com.yahoo.sketches.tuple.DoubleSummaryFactory in project sketches-pig by DataSketches.

the class DoubleSummarySketchToEstimatesTest method normalCase.

@Test
public void normalCase() throws Exception {
    EvalFunc<Tuple> func = new DoubleSummarySketchToEstimates();
    UpdatableSketch<Double, DoubleSummary> sketch = new UpdatableSketchBuilder<Double, DoubleSummary>(new DoubleSummaryFactory()).build();
    int iterations = 100000;
    for (int i = 0; i < iterations; i++) sketch.update(i, 1.0);
    for (int i = 0; i < iterations; i++) sketch.update(i, 1.0);
    Tuple inputTuple = PigUtil.objectsToTuple(new DataByteArray(sketch.compact().toByteArray()));
    Tuple resultTuple = func.exec(inputTuple);
    Assert.assertNotNull(resultTuple);
    Assert.assertEquals(resultTuple.size(), 2);
    Assert.assertEquals((double) resultTuple.get(0), iterations, iterations * 0.03);
    Assert.assertEquals((double) resultTuple.get(1), 2 * iterations, 2 * iterations * 0.03);
}
Also used : DoubleSummary(com.yahoo.sketches.tuple.DoubleSummary) DoubleSummaryFactory(com.yahoo.sketches.tuple.DoubleSummaryFactory) DataByteArray(org.apache.pig.data.DataByteArray) Tuple(org.apache.pig.data.Tuple) Test(org.testng.annotations.Test)

Example 2 with DoubleSummaryFactory

use of com.yahoo.sketches.tuple.DoubleSummaryFactory in project sketches-pig by DataSketches.

the class DoubleSummarySketchToPercentileTest method emptySketch.

@Test
public void emptySketch() throws Exception {
    EvalFunc<Double> func = new DoubleSummarySketchToPercentile();
    UpdatableSketch<Double, DoubleSummary> sketch = new UpdatableSketchBuilder<Double, DoubleSummary>(new DoubleSummaryFactory()).build();
    Tuple inputTuple = TupleFactory.getInstance().newTuple(Arrays.asList(new DataByteArray(sketch.compact().toByteArray()), 0.0));
    double result = func.exec(inputTuple);
    Assert.assertEquals(result, Double.NaN);
}
Also used : DoubleSummary(com.yahoo.sketches.tuple.DoubleSummary) DoubleSummaryFactory(com.yahoo.sketches.tuple.DoubleSummaryFactory) DataByteArray(org.apache.pig.data.DataByteArray) Tuple(org.apache.pig.data.Tuple) Test(org.testng.annotations.Test)

Example 3 with DoubleSummaryFactory

use of com.yahoo.sketches.tuple.DoubleSummaryFactory in project sketches-pig by DataSketches.

the class UnionDoubleSummarySketchTest method exec.

@Test
public void exec() throws Exception {
    EvalFunc<Tuple> func = new UnionDoubleSummarySketch("4096");
    DataBag bag = BagFactory.getInstance().newDefaultBag();
    {
        UpdatableSketch<Double, DoubleSummary> sketch = new UpdatableSketchBuilder<Double, DoubleSummary>(new DoubleSummaryFactory()).build();
        sketch.update(1, 1.0);
        sketch.update(2, 1.0);
        bag.add(PigUtil.objectsToTuple(new DataByteArray(sketch.compact().toByteArray())));
    }
    {
        UpdatableSketch<Double, DoubleSummary> sketch = new UpdatableSketchBuilder<Double, DoubleSummary>(new DoubleSummaryFactory()).build();
        sketch.update(1, 1.0);
        sketch.update(2, 1.0);
        bag.add(PigUtil.objectsToTuple(new DataByteArray(sketch.compact().toByteArray())));
    }
    Tuple resultTuple = func.exec(PigUtil.objectsToTuple(bag));
    Assert.assertNotNull(resultTuple);
    Assert.assertEquals(resultTuple.size(), 1);
    DataByteArray bytes = (DataByteArray) resultTuple.get(0);
    Assert.assertTrue(bytes.size() > 0);
    Sketch<DoubleSummary> sketch = Sketches.heapifySketch(Memory.wrap(bytes.get()), new DoubleSummaryDeserializer());
    Assert.assertEquals(sketch.getEstimate(), 2.0, 0.0);
    SketchIterator<DoubleSummary> it = sketch.iterator();
    while (it.next()) {
        Assert.assertEquals(it.getSummary().getValue(), 2.0, 0.0);
    }
}
Also used : UpdatableSketch(com.yahoo.sketches.tuple.UpdatableSketch) DataBag(org.apache.pig.data.DataBag) DoubleSummary(com.yahoo.sketches.tuple.DoubleSummary) UpdatableSketchBuilder(com.yahoo.sketches.tuple.UpdatableSketchBuilder) DoubleSummaryDeserializer(com.yahoo.sketches.tuple.DoubleSummaryDeserializer) DoubleSummaryFactory(com.yahoo.sketches.tuple.DoubleSummaryFactory) DataByteArray(org.apache.pig.data.DataByteArray) Tuple(org.apache.pig.data.Tuple) Test(org.testng.annotations.Test)

Example 4 with DoubleSummaryFactory

use of com.yahoo.sketches.tuple.DoubleSummaryFactory in project sketches-pig by DataSketches.

the class UnionDoubleSummarySketchTest method execMaxMode.

@Test
public void execMaxMode() throws Exception {
    EvalFunc<Tuple> func = new UnionDoubleSummarySketch("4096", "Max");
    DataBag bag = BagFactory.getInstance().newDefaultBag();
    {
        UpdatableSketch<Double, DoubleSummary> sketch = new UpdatableSketchBuilder<Double, DoubleSummary>(new DoubleSummaryFactory()).build();
        sketch.update(1, 1.0);
        sketch.update(2, 1.0);
        bag.add(PigUtil.objectsToTuple(new DataByteArray(sketch.compact().toByteArray())));
    }
    {
        UpdatableSketch<Double, DoubleSummary> sketch = new UpdatableSketchBuilder<Double, DoubleSummary>(new DoubleSummaryFactory()).build();
        sketch.update(1, 3.0);
        sketch.update(2, 3.0);
        bag.add(PigUtil.objectsToTuple(new DataByteArray(sketch.compact().toByteArray())));
    }
    Tuple resultTuple = func.exec(PigUtil.objectsToTuple(bag));
    Assert.assertNotNull(resultTuple);
    Assert.assertEquals(resultTuple.size(), 1);
    DataByteArray bytes = (DataByteArray) resultTuple.get(0);
    Assert.assertTrue(bytes.size() > 0);
    Sketch<DoubleSummary> sketch = Sketches.heapifySketch(Memory.wrap(bytes.get()), new DoubleSummaryDeserializer());
    Assert.assertEquals(sketch.getEstimate(), 2.0, 0.0);
    SketchIterator<DoubleSummary> it = sketch.iterator();
    while (it.next()) {
        Assert.assertEquals(it.getSummary().getValue(), 3.0, 0.0);
    }
}
Also used : UpdatableSketch(com.yahoo.sketches.tuple.UpdatableSketch) DataBag(org.apache.pig.data.DataBag) DoubleSummary(com.yahoo.sketches.tuple.DoubleSummary) UpdatableSketchBuilder(com.yahoo.sketches.tuple.UpdatableSketchBuilder) DoubleSummaryDeserializer(com.yahoo.sketches.tuple.DoubleSummaryDeserializer) DoubleSummaryFactory(com.yahoo.sketches.tuple.DoubleSummaryFactory) DataByteArray(org.apache.pig.data.DataByteArray) Tuple(org.apache.pig.data.Tuple) Test(org.testng.annotations.Test)

Example 5 with DoubleSummaryFactory

use of com.yahoo.sketches.tuple.DoubleSummaryFactory in project sketches-pig by DataSketches.

the class UnionDoubleSummarySketchTest method algebraicIntemediateFinalExactMinMode.

@Test
public void algebraicIntemediateFinalExactMinMode() throws Exception {
    EvalFunc<Tuple> func = new UnionDoubleSummarySketch.IntermediateFinal("4096", "Min");
    DataBag bag = BagFactory.getInstance().newDefaultBag();
    // this is to simulate the output from Initial
    {
        UpdatableSketch<Double, DoubleSummary> sketch = new UpdatableSketchBuilder<Double, DoubleSummary>(new DoubleSummaryFactory()).build();
        sketch.update(1, 1.0);
        sketch.update(2, 1.0);
        DataBag innerBag = PigUtil.tuplesToBag(PigUtil.objectsToTuple(new DataByteArray(sketch.compact().toByteArray())));
        bag.add(PigUtil.objectsToTuple(innerBag));
    }
    // this is to simulate the output from a prior call of IntermediateFinal
    {
        UpdatableSketch<Double, DoubleSummary> sketch = new UpdatableSketchBuilder<Double, DoubleSummary>(new DoubleSummaryFactory()).build();
        sketch.update(1, 3.0);
        sketch.update(2, 3.0);
        bag.add(PigUtil.objectsToTuple(new DataByteArray(sketch.compact().toByteArray())));
    }
    Tuple resultTuple = func.exec(PigUtil.objectsToTuple(bag));
    Assert.assertNotNull(resultTuple);
    Assert.assertEquals(resultTuple.size(), 1);
    DataByteArray bytes = (DataByteArray) resultTuple.get(0);
    Assert.assertTrue(bytes.size() > 0);
    Sketch<DoubleSummary> sketch = Sketches.heapifySketch(Memory.wrap(bytes.get()), new DoubleSummaryDeserializer());
    Assert.assertEquals(sketch.getEstimate(), 2.0, 0.0);
    SketchIterator<DoubleSummary> it = sketch.iterator();
    while (it.next()) {
        Assert.assertEquals(it.getSummary().getValue(), 1.0, 0.0);
    }
}
Also used : UpdatableSketch(com.yahoo.sketches.tuple.UpdatableSketch) DataBag(org.apache.pig.data.DataBag) DoubleSummary(com.yahoo.sketches.tuple.DoubleSummary) UpdatableSketchBuilder(com.yahoo.sketches.tuple.UpdatableSketchBuilder) DoubleSummaryDeserializer(com.yahoo.sketches.tuple.DoubleSummaryDeserializer) DoubleSummaryFactory(com.yahoo.sketches.tuple.DoubleSummaryFactory) DataByteArray(org.apache.pig.data.DataByteArray) Tuple(org.apache.pig.data.Tuple) Test(org.testng.annotations.Test)

Aggregations

DoubleSummary (com.yahoo.sketches.tuple.DoubleSummary)13 DoubleSummaryFactory (com.yahoo.sketches.tuple.DoubleSummaryFactory)13 DataByteArray (org.apache.pig.data.DataByteArray)13 Tuple (org.apache.pig.data.Tuple)13 Test (org.testng.annotations.Test)13 DoubleSummaryDeserializer (com.yahoo.sketches.tuple.DoubleSummaryDeserializer)9 DataBag (org.apache.pig.data.DataBag)9 UpdatableSketch (com.yahoo.sketches.tuple.UpdatableSketch)8 UpdatableSketchBuilder (com.yahoo.sketches.tuple.UpdatableSketchBuilder)5 Random (java.util.Random)1