Search in sources :

Example 11 with UpdateDoublesSketch

use of com.yahoo.sketches.quantiles.UpdateDoublesSketch in project sketches-pig by DataSketches.

the class DataToDoublesSketchTest method algebraicIntermediateFinalNormalCase.

@Test
public void algebraicIntermediateFinalNormalCase() throws Exception {
    EvalFunc<Tuple> func = new DataToDoublesSketch.IntermediateFinal();
    DataBag bag = bagFactory.newDefaultBag();
    {
        // this is to simulate an output from Initial
        DataBag innerBag = bagFactory.newDefaultBag();
        innerBag.add(tupleFactory.newTuple(1.0));
        bag.add(tupleFactory.newTuple(innerBag));
    }
    {
        // this is to simulate an output from a prior call of IntermediateFinal
        UpdateDoublesSketch qs = DoublesSketch.builder().build();
        qs.update(2.0);
        bag.add(tupleFactory.newTuple(new DataByteArray(qs.toByteArray())));
    }
    Tuple resultTuple = func.exec(tupleFactory.newTuple(bag));
    DoublesSketch sketch = getSketch(resultTuple);
    Assert.assertFalse(sketch.isEmpty());
    Assert.assertEquals(sketch.getN(), 2);
}
Also used : DoublesSketch(com.yahoo.sketches.quantiles.DoublesSketch) UpdateDoublesSketch(com.yahoo.sketches.quantiles.UpdateDoublesSketch) DataBag(org.apache.pig.data.DataBag) UpdateDoublesSketch(com.yahoo.sketches.quantiles.UpdateDoublesSketch) DataByteArray(org.apache.pig.data.DataByteArray) Tuple(org.apache.pig.data.Tuple) Test(org.testng.annotations.Test)

Example 12 with UpdateDoublesSketch

use of com.yahoo.sketches.quantiles.UpdateDoublesSketch in project sketches-pig by DataSketches.

the class GetQuantilesFromDoublesSketchTest method numberOfEvenlySpacedIntervals.

@Test
public void numberOfEvenlySpacedIntervals() throws Exception {
    EvalFunc<Tuple> func = new GetQuantilesFromDoublesSketch();
    UpdateDoublesSketch sketch = DoublesSketch.builder().build();
    for (int i = 1; i <= 10; i++) sketch.update(i);
    Tuple resultTuple = func.exec(tupleFactory.newTuple(Arrays.asList(new DataByteArray(sketch.toByteArray()), 3)));
    Assert.assertNotNull(resultTuple);
    Assert.assertEquals(resultTuple.size(), 3);
    Assert.assertEquals(((double) resultTuple.get(0)), 1.0);
    Assert.assertEquals(((double) resultTuple.get(1)), 6.0);
    Assert.assertEquals(((double) resultTuple.get(2)), 10.0);
}
Also used : UpdateDoublesSketch(com.yahoo.sketches.quantiles.UpdateDoublesSketch) DataByteArray(org.apache.pig.data.DataByteArray) Tuple(org.apache.pig.data.Tuple) Test(org.testng.annotations.Test)

Example 13 with UpdateDoublesSketch

use of com.yahoo.sketches.quantiles.UpdateDoublesSketch in project sketches-pig by DataSketches.

the class UnionDoublesSketchTest method algebraicIntermediateFinalNormalCase.

@Test
public void algebraicIntermediateFinalNormalCase() throws Exception {
    EvalFunc<Tuple> func = new UnionDoublesSketch.IntermediateFinal();
    DataBag bag = bagFactory.newDefaultBag();
    {
        // this is to simulate an output from Initial
        DataBag innerBag = bagFactory.newDefaultBag();
        UpdateDoublesSketch qs = DoublesSketch.builder().build();
        qs.update(1.0);
        innerBag.add(tupleFactory.newTuple(new DataByteArray(qs.toByteArray())));
        bag.add(tupleFactory.newTuple(innerBag));
    }
    {
        // this is to simulate an output from a prior call of IntermediateFinal
        UpdateDoublesSketch qs = DoublesSketch.builder().build();
        qs.update(2.0);
        bag.add(tupleFactory.newTuple(new DataByteArray(qs.toByteArray())));
    }
    Tuple resultTuple = func.exec(tupleFactory.newTuple(bag));
    DoublesSketch sketch = getSketch(resultTuple);
    Assert.assertFalse(sketch.isEmpty());
    Assert.assertEquals(sketch.getN(), 2);
}
Also used : DoublesSketch(com.yahoo.sketches.quantiles.DoublesSketch) UpdateDoublesSketch(com.yahoo.sketches.quantiles.UpdateDoublesSketch) DataBag(org.apache.pig.data.DataBag) UpdateDoublesSketch(com.yahoo.sketches.quantiles.UpdateDoublesSketch) DataByteArray(org.apache.pig.data.DataByteArray) Tuple(org.apache.pig.data.Tuple) Test(org.testng.annotations.Test)

Example 14 with UpdateDoublesSketch

use of com.yahoo.sketches.quantiles.UpdateDoublesSketch in project Gaffer by gchq.

the class DoublesSketchAggregatorTest method testAggregate.

@Test
public void testAggregate() {
    final DoublesSketchAggregator sketchAggregator = new DoublesSketchAggregator();
    UpdateDoublesSketch sketch1 = DoublesSketch.builder().build();
    sketch1.update(1.0D);
    sketch1.update(2.0D);
    sketch1.update(3.0D);
    DoublesSketch currentState = sketch1;
    assertEquals(3L, currentState.getN());
    assertEquals(2.0D, currentState.getQuantile(0.5D), DELTA);
    UpdateDoublesSketch sketch2 = DoublesSketch.builder().build();
    sketch2.update(4.0D);
    sketch2.update(5.0D);
    sketch2.update(6.0D);
    sketch2.update(7.0D);
    currentState = sketchAggregator.apply(currentState, sketch2);
    assertEquals(7L, currentState.getN());
    assertEquals(4.0D, currentState.getQuantile(0.5D), DELTA);
}
Also used : DoublesSketch(com.yahoo.sketches.quantiles.DoublesSketch) UpdateDoublesSketch(com.yahoo.sketches.quantiles.UpdateDoublesSketch) UpdateDoublesSketch(com.yahoo.sketches.quantiles.UpdateDoublesSketch) Test(org.junit.jupiter.api.Test) BinaryOperatorTest(uk.gov.gchq.koryphe.binaryoperator.BinaryOperatorTest)

Aggregations

UpdateDoublesSketch (com.yahoo.sketches.quantiles.UpdateDoublesSketch)14 DataByteArray (org.apache.pig.data.DataByteArray)11 Test (org.testng.annotations.Test)9 Tuple (org.apache.pig.data.Tuple)8 DoublesSketch (com.yahoo.sketches.quantiles.DoublesSketch)6 DataBag (org.apache.pig.data.DataBag)4 Test (org.junit.jupiter.api.Test)2 DoublesSketchBuilder (com.yahoo.sketches.quantiles.DoublesSketchBuilder)1 ArrayOfDoublesSketch (com.yahoo.sketches.tuple.ArrayOfDoublesSketch)1 ArrayOfDoublesSketchIterator (com.yahoo.sketches.tuple.ArrayOfDoublesSketchIterator)1 DoubleSummary (com.yahoo.sketches.tuple.DoubleSummary)1 ArrayList (java.util.ArrayList)1 Edge (uk.gov.gchq.gaffer.data.element.Edge)1 Element (uk.gov.gchq.gaffer.data.element.Element)1 BinaryOperatorTest (uk.gov.gchq.koryphe.binaryoperator.BinaryOperatorTest)1