Search in sources :

Example 26 with ArrayOfDoublesUpdatableSketch

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

the class ArrayOfDoublesSketchToEstimatesTest method normalCase.

@Test
public void normalCase() throws Exception {
    EvalFunc<Tuple> func = new ArrayOfDoublesSketchToEstimates();
    ArrayOfDoublesUpdatableSketch sketch = new ArrayOfDoublesUpdatableSketchBuilder().build();
    int iterations = 100000;
    for (int i = 0; i < iterations; i++) sketch.update(i, new double[] { 1 });
    for (int i = 0; i < iterations; i++) sketch.update(i, new double[] { 1 });
    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 : ArrayOfDoublesUpdatableSketchBuilder(com.yahoo.sketches.tuple.ArrayOfDoublesUpdatableSketchBuilder) ArrayOfDoublesUpdatableSketch(com.yahoo.sketches.tuple.ArrayOfDoublesUpdatableSketch) DataByteArray(org.apache.pig.data.DataByteArray) Tuple(org.apache.pig.data.Tuple) Test(org.testng.annotations.Test)

Example 27 with ArrayOfDoublesUpdatableSketch

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

the class ArrayOfDoublesSketchToMeansTest method emptyInputSketch.

@Test
public void emptyInputSketch() throws Exception {
    EvalFunc<Tuple> func = new ArrayOfDoublesSketchToMeans();
    ArrayOfDoublesUpdatableSketch sketch = new ArrayOfDoublesUpdatableSketchBuilder().build();
    Tuple inputTuple = PigUtil.objectsToTuple(new DataByteArray(sketch.compact().toByteArray()));
    Tuple resultTuple = func.exec(inputTuple);
    Assert.assertNull(resultTuple);
}
Also used : ArrayOfDoublesUpdatableSketchBuilder(com.yahoo.sketches.tuple.ArrayOfDoublesUpdatableSketchBuilder) ArrayOfDoublesUpdatableSketch(com.yahoo.sketches.tuple.ArrayOfDoublesUpdatableSketch) DataByteArray(org.apache.pig.data.DataByteArray) Tuple(org.apache.pig.data.Tuple) Test(org.testng.annotations.Test)

Example 28 with ArrayOfDoublesUpdatableSketch

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

the class ArrayOfDoublesSketchToNumberOfRetainedEntriesTest method nonEmptyInputSketch.

@Test
public void nonEmptyInputSketch() throws Exception {
    EvalFunc<Integer> func = new ArrayOfDoublesSketchToNumberOfRetainedEntries();
    ArrayOfDoublesUpdatableSketch sketch = new ArrayOfDoublesUpdatableSketchBuilder().build();
    sketch.update(1, new double[] { 0 });
    Integer result = func.exec(tupleFactory.newTuple(new DataByteArray(sketch.compact().toByteArray())));
    Assert.assertNotNull(result);
    Assert.assertEquals((int) result, 1);
}
Also used : ArrayOfDoublesUpdatableSketchBuilder(com.yahoo.sketches.tuple.ArrayOfDoublesUpdatableSketchBuilder) ArrayOfDoublesUpdatableSketch(com.yahoo.sketches.tuple.ArrayOfDoublesUpdatableSketch) DataByteArray(org.apache.pig.data.DataByteArray) Test(org.testng.annotations.Test)

Example 29 with ArrayOfDoublesUpdatableSketch

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

the class ArrayOfDoublesSketchToQuantilesSketchTest method nonEmptyInputSketchWithTwoColumnsExplicitK.

@Test
public void nonEmptyInputSketchWithTwoColumnsExplicitK() throws Exception {
    int k = 256;
    EvalFunc<DataByteArray> func = new ArrayOfDoublesSketchToQuantilesSketch(Integer.toString(k));
    ArrayOfDoublesUpdatableSketch sketch = new ArrayOfDoublesUpdatableSketchBuilder().setNumberOfValues(2).build();
    sketch.update(1, new double[] { 1.0, 2.0 });
    sketch.update(2, new double[] { 10.0, 20.0 });
    DataByteArray result = func.exec(tupleFactory.newTuple(Arrays.asList(new DataByteArray(sketch.compact().toByteArray()), 2)));
    Assert.assertNotNull(result);
    DoublesSketch quantilesSketch = DoublesSketch.wrap(Memory.wrap(result.get()));
    Assert.assertFalse(quantilesSketch.isEmpty());
    Assert.assertEquals(quantilesSketch.getK(), k);
    Assert.assertEquals(quantilesSketch.getMinValue(), 2.0);
    Assert.assertEquals(quantilesSketch.getMaxValue(), 20.0);
}
Also used : DoublesSketch(com.yahoo.sketches.quantiles.DoublesSketch) ArrayOfDoublesUpdatableSketchBuilder(com.yahoo.sketches.tuple.ArrayOfDoublesUpdatableSketchBuilder) ArrayOfDoublesUpdatableSketch(com.yahoo.sketches.tuple.ArrayOfDoublesUpdatableSketch) DataByteArray(org.apache.pig.data.DataByteArray) Test(org.testng.annotations.Test)

Example 30 with ArrayOfDoublesUpdatableSketch

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

the class ArrayOfDoublesSketchToQuantilesSketchTest method emptyInputSketch.

@Test
public void emptyInputSketch() throws Exception {
    EvalFunc<DataByteArray> func = new ArrayOfDoublesSketchToQuantilesSketch();
    ArrayOfDoublesUpdatableSketch sketch = new ArrayOfDoublesUpdatableSketchBuilder().build();
    DataByteArray result = func.exec(tupleFactory.newTuple(new DataByteArray(sketch.compact().toByteArray())));
    Assert.assertNotNull(result);
    DoublesSketch quantilesSketch = DoublesSketch.wrap(Memory.wrap(result.get()));
    Assert.assertTrue(quantilesSketch.isEmpty());
}
Also used : DoublesSketch(com.yahoo.sketches.quantiles.DoublesSketch) ArrayOfDoublesUpdatableSketchBuilder(com.yahoo.sketches.tuple.ArrayOfDoublesUpdatableSketchBuilder) ArrayOfDoublesUpdatableSketch(com.yahoo.sketches.tuple.ArrayOfDoublesUpdatableSketch) DataByteArray(org.apache.pig.data.DataByteArray) Test(org.testng.annotations.Test)

Aggregations

ArrayOfDoublesUpdatableSketch (com.yahoo.sketches.tuple.ArrayOfDoublesUpdatableSketch)31 ArrayOfDoublesUpdatableSketchBuilder (com.yahoo.sketches.tuple.ArrayOfDoublesUpdatableSketchBuilder)31 DataByteArray (org.apache.pig.data.DataByteArray)31 Test (org.testng.annotations.Test)29 Tuple (org.apache.pig.data.Tuple)26 DataBag (org.apache.pig.data.DataBag)10 ArrayOfDoublesSketch (com.yahoo.sketches.tuple.ArrayOfDoublesSketch)8 TTest (org.apache.commons.math3.stat.inference.TTest)6 Random (java.util.Random)4 DoublesSketch (com.yahoo.sketches.quantiles.DoublesSketch)2 ArrayOfDoublesSetOperationBuilder (com.yahoo.sketches.tuple.ArrayOfDoublesSetOperationBuilder)1 ArrayOfDoublesUnion (com.yahoo.sketches.tuple.ArrayOfDoublesUnion)1