Search in sources :

Example 26 with BulletRecord

use of com.yahoo.bullet.record.BulletRecord in project bullet-core by yahoo.

the class QuantileSketchTest method testResetting.

@Test
public void testResetting() {
    QuantileSketch sketch = new QuantileSketch(64, Distribution.Type.CDF, makePoints(0.0, 9.0, 1.0));
    IntStream.range(0, 30).forEach(i -> sketch.update(i % 10));
    QuantileSketch anotherSketch = new QuantileSketch(64, Distribution.Type.CDF, makePoints(0.0, 9.0, 1.0));
    IntStream.range(0, 30).forEach(i -> sketch.update(i % 3));
    sketch.union(anotherSketch.serialize());
    Clip result = sketch.getResult(null, null);
    List<BulletRecord> records = result.getRecords();
    for (BulletRecord record : records) {
        String range = (String) record.get(RANGE_FIELD);
        double count = (Double) record.get(COUNT_FIELD);
        String rangeEnd = getEnd(range);
        if (rangeEnd.equals(POSITIVE_INFINITY)) {
            Assert.assertEquals(count, 60.0);
        } else {
            double end = Double.valueOf(rangeEnd);
            if (end <= 3.0) {
                Assert.assertEquals(count, end * 13.0);
            } else {
                Assert.assertEquals(count, 39.0 + (end - 3) * 3.0);
            }
        }
    }
    sketch.reset();
    sketch.update(1.0);
    result = sketch.getResult(null, null);
    records = result.getRecords();
    for (BulletRecord record : records) {
        String range = (String) record.get(RANGE_FIELD);
        double count = (Double) record.get(COUNT_FIELD);
        String rangeEnd = getEnd(range);
        if (rangeEnd.equals(POSITIVE_INFINITY)) {
            Assert.assertEquals(count, 1.0);
        } else {
            double end = Double.valueOf(rangeEnd);
            if (end <= 1.0) {
                Assert.assertEquals(count, 0.0);
            } else {
                Assert.assertEquals(count, 1.0);
            }
        }
    }
}
Also used : Clip(com.yahoo.bullet.result.Clip) BulletRecord(com.yahoo.bullet.record.BulletRecord) Test(org.testng.annotations.Test)

Example 27 with BulletRecord

use of com.yahoo.bullet.record.BulletRecord in project bullet-core by yahoo.

the class QuantileSketchTest method testExactQuantilesWithProvidedPoints.

@Test
public void testExactQuantilesWithProvidedPoints() {
    // Same results as the testExactQuantilesWithNumberOfPoints
    QuantileSketch sketch = new QuantileSketch(64, Distribution.Type.QUANTILE, makePoints(0.0, 1.0, 0.1));
    IntStream.range(0, 11).forEach(i -> sketch.update(i * 10.0));
    List<BulletRecord> records = sketch.getResult(null, null).getRecords();
    for (BulletRecord record : records) {
        Double quantile = (Double) record.get(QUANTILE_FIELD);
        Double value = (Double) record.get(VALUE_FIELD);
        double percent = quantile * 100;
        assertApproxEquals(percent, value);
    }
}
Also used : BulletRecord(com.yahoo.bullet.record.BulletRecord) Test(org.testng.annotations.Test)

Example 28 with BulletRecord

use of com.yahoo.bullet.record.BulletRecord in project bullet-core by yahoo.

the class ThetaSketchTest method testResetting.

@Test
public void testResetting() {
    ThetaSketch sketch = new ThetaSketch(ResizeFactor.X4, Family.ALPHA, 1.0f, 512);
    sketch.update("foo");
    sketch.update("bar");
    sketch.update("baz");
    List<BulletRecord> actuals = sketch.getResult(null, null).getRecords();
    Assert.assertEquals(actuals.size(), 1);
    BulletRecord expected = RecordBox.get().add(ThetaSketch.COUNT_FIELD, 3.0).getRecord();
    BulletRecord actual = actuals.get(0);
    Assert.assertEquals(actual, expected);
    sketch.reset();
    actuals = sketch.getResult(null, null).getRecords();
    Assert.assertEquals(actuals.size(), 1);
    expected = RecordBox.get().add(ThetaSketch.COUNT_FIELD, 0.0).getRecord();
    actual = actuals.get(0);
    Assert.assertEquals(actual, expected);
    ThetaSketch anotherSketch = new ThetaSketch(ResizeFactor.X4, Family.ALPHA, 1.0f, 512);
    IntStream.range(0, 41).forEach(i -> anotherSketch.update(String.valueOf(i)));
    sketch.union(anotherSketch.serialize());
    sketch.update("foo");
    actuals = sketch.getResult(null, null).getRecords();
    Assert.assertEquals(actuals.size(), 1);
    expected = RecordBox.get().add(ThetaSketch.COUNT_FIELD, 42.0).getRecord();
    actual = actuals.get(0);
    Assert.assertEquals(actual, expected);
}
Also used : BulletRecord(com.yahoo.bullet.record.BulletRecord) Test(org.testng.annotations.Test)

Example 29 with BulletRecord

use of com.yahoo.bullet.record.BulletRecord in project bullet-core by yahoo.

the class ThetaSketchTest method testUpdatingForExactResult.

@Test
public void testUpdatingForExactResult() {
    ThetaSketch sketch = new ThetaSketch(ResizeFactor.X4, Family.ALPHA, 1.0f, 512);
    sketch.update("foo");
    sketch.update("bar");
    sketch.update("baz");
    List<BulletRecord> actuals = sketch.getResult(null, null).getRecords();
    Assert.assertEquals(actuals.size(), 1);
    BulletRecord expected = RecordBox.get().add(ThetaSketch.COUNT_FIELD, 3.0).getRecord();
    BulletRecord actual = actuals.get(0);
    Assert.assertEquals(actual, expected);
}
Also used : BulletRecord(com.yahoo.bullet.record.BulletRecord) Test(org.testng.annotations.Test)

Example 30 with BulletRecord

use of com.yahoo.bullet.record.BulletRecord in project bullet-core by yahoo.

the class TupleSketchTest method testResetting.

@Test
public void testResetting() {
    data = new CachingGroupData(null, new HashMap<>());
    TupleSketch sketch = new TupleSketch(ResizeFactor.X4, 1.0f, 32, 16);
    sketch.update(addToData("foo", 0.0, data), data);
    sketch.update(addToData("bar", 0.2, data), data);
    TupleSketch anotherSketch = new TupleSketch(ResizeFactor.X4, 1.0f, 32, 16);
    sketch.update(addToData("bar", 0.2, data), data);
    sketch.update(addToData("baz", 0.2, data), data);
    sketch.update(addToData("qux", 0.2, data), data);
    sketch.union(anotherSketch.serialize());
    List<BulletRecord> actuals = sketch.getResult(null, null).getRecords();
    Assert.assertEquals(actuals.size(), 4);
    BulletRecord expectedA = RecordBox.get().add("A", "foo").add("B", "0.0").getRecord();
    BulletRecord expectedB = RecordBox.get().add("A", "bar").add("B", "0.2").getRecord();
    BulletRecord expectedC = RecordBox.get().add("A", "baz").add("B", "0.2").getRecord();
    BulletRecord expectedD = RecordBox.get().add("A", "qux").add("B", "0.2").getRecord();
    TestHelpers.assertContains(actuals, expectedA);
    TestHelpers.assertContains(actuals, expectedB);
    TestHelpers.assertContains(actuals, expectedC);
    TestHelpers.assertContains(actuals, expectedD);
    sketch.reset();
    sketch.update(addToData("foo", 0.0, data), data);
    sketch.update(addToData("bar", 0.2, data), data);
    actuals = sketch.getResult(null, null).getRecords();
    Assert.assertEquals(actuals.size(), 2);
    expectedA = RecordBox.get().add("A", "foo").add("B", "0.0").getRecord();
    expectedB = RecordBox.get().add("A", "bar").add("B", "0.2").getRecord();
    TestHelpers.assertContains(actuals, expectedA);
    TestHelpers.assertContains(actuals, expectedB);
}
Also used : BulletRecord(com.yahoo.bullet.record.BulletRecord) HashMap(java.util.HashMap) CachingGroupData(com.yahoo.bullet.aggregations.grouping.CachingGroupData) Test(org.testng.annotations.Test)

Aggregations

BulletRecord (com.yahoo.bullet.record.BulletRecord)210 Test (org.testng.annotations.Test)196 Tuple (org.apache.storm.tuple.Tuple)55 CountDistinctTest (com.yahoo.bullet.aggregations.CountDistinctTest)53 DistributionTest (com.yahoo.bullet.aggregations.DistributionTest)53 TopKTest (com.yahoo.bullet.aggregations.TopKTest)53 Clip (com.yahoo.bullet.result.Clip)53 HashMap (java.util.HashMap)53 Map (java.util.Map)53 BulletConfig (com.yahoo.bullet.common.BulletConfig)46 List (java.util.List)45 IntStream (java.util.stream.IntStream)45 Assert (org.testng.Assert)45 RecordBox (com.yahoo.bullet.result.RecordBox)43 Arrays.asList (java.util.Arrays.asList)40 Pair (org.apache.commons.lang3.tuple.Pair)40 AggregationUtils.makeAttributes (com.yahoo.bullet.parsing.AggregationUtils.makeAttributes)34 BulletError (com.yahoo.bullet.common.BulletError)33 Aggregation (com.yahoo.bullet.parsing.Aggregation)33 Concept (com.yahoo.bullet.result.Meta.Concept)33