Search in sources :

Example 16 with BulletRecord

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

the class GroupDataTest method testMultiSumOfLongs.

@Test
public void testMultiSumOfLongs() {
    GroupData data = make(new GroupOperation(GroupOperation.GroupOperationType.SUM, "someField", "foo"));
    List<Long> numbers = asList(0L, 8L, -88L, 51L, 4L);
    numbers.stream().map(x -> RecordBox.get().add("someField", x).getRecord()).forEach(data::consume);
    BulletRecord expected = RecordBox.get().add("foo", -25.0).getRecord();
    Assert.assertEquals(data.getMetricsAsBulletRecord(), expected);
}
Also used : IntStream(java.util.stream.IntStream) BulletRecord(com.yahoo.bullet.record.BulletRecord) SerializerDeserializer(com.yahoo.bullet.common.SerializerDeserializer) Test(org.testng.annotations.Test) HashMap(java.util.HashMap) RecordBox(com.yahoo.bullet.result.RecordBox) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) List(java.util.List) Pair(org.apache.commons.lang3.tuple.Pair) Assert(org.testng.Assert) Arrays.asList(java.util.Arrays.asList) BulletConfig(com.yahoo.bullet.common.BulletConfig) Map(java.util.Map) Collections(java.util.Collections) BulletRecord(com.yahoo.bullet.record.BulletRecord) Test(org.testng.annotations.Test)

Example 17 with BulletRecord

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

the class GroupDataTest method testNullRecordCount.

@Test
public void testNullRecordCount() {
    GroupData data = make(new GroupOperation(GroupOperation.GroupOperationType.COUNT, null, "count"));
    data.consume(RecordBox.get().add("foo", "bar").getRecord());
    // We do not expect to send in null records so the count is incremented.
    BulletRecord expected = RecordBox.get().add("count", 1L).getRecord();
    Assert.assertEquals(data.getMetricsAsBulletRecord(), expected);
}
Also used : BulletRecord(com.yahoo.bullet.record.BulletRecord) Test(org.testng.annotations.Test)

Example 18 with BulletRecord

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

the class FrequentItemsSketchTest method testExactCounting.

@Test
public void testExactCounting() {
    FrequentItemsSketch sketch = new FrequentItemsSketch(ErrorType.NO_FALSE_NEGATIVES, 32, 15);
    IntStream.range(0, 10).forEach(i -> IntStream.range(0, 10).forEach(j -> sketch.update(String.valueOf(i))));
    sketch.update("foo");
    IntStream.range(10, 100).forEach(i -> sketch.update("bar"));
    sketch.update("baz");
    Clip result = sketch.getResult("meta", ALL_METADATA);
    Map<String, Object> metadata = (Map<String, Object>) result.getMeta().asMap().get("meta");
    Assert.assertEquals(metadata.size(), 5);
    Assert.assertFalse((Boolean) metadata.get("isEst"));
    Assert.assertEquals((String) metadata.get("family"), Family.FREQUENCY.getFamilyName());
    Assert.assertNull(metadata.get("size"));
    Assert.assertEquals(metadata.get("error"), 0L);
    Assert.assertEquals(metadata.get("n"), 192L);
    Assert.assertEquals(metadata.get("actives"), 13);
    List<BulletRecord> records = result.getRecords();
    Assert.assertEquals(records.size(), 13);
    for (BulletRecord actual : records) {
        String item = actual.get(FrequentItemsSketch.ITEM_FIELD).toString();
        Assert.assertEquals(actual.fieldCount(), 2);
        if ("bar".equals(item)) {
            Assert.assertEquals(actual.get(FrequentItemsSketch.COUNT_FIELD), 90L);
        } else if ("foo".equals(item) || "baz".equals(item)) {
            Assert.assertEquals(actual.get(FrequentItemsSketch.COUNT_FIELD), 1L);
        } else if (Integer.valueOf(item) < 10) {
            Assert.assertEquals(actual.get(FrequentItemsSketch.COUNT_FIELD), 10L);
        } else {
            Assert.fail("This should not be a case");
        }
    }
    Assert.assertEquals(sketch.getRecords(), result.getRecords());
    Assert.assertEquals(sketch.getMetadata("meta", ALL_METADATA).asMap(), result.getMeta().asMap());
}
Also used : IntStream(java.util.stream.IntStream) List(java.util.List) Assert(org.testng.Assert) BulletRecord(com.yahoo.bullet.record.BulletRecord) SketchesArgumentException(com.yahoo.sketches.SketchesArgumentException) Meta(com.yahoo.bullet.result.Meta) Map(java.util.Map) Test(org.testng.annotations.Test) HashMap(java.util.HashMap) ErrorType(com.yahoo.sketches.frequencies.ErrorType) Clip(com.yahoo.bullet.result.Clip) Family(com.yahoo.sketches.Family) Clip(com.yahoo.bullet.result.Clip) BulletRecord(com.yahoo.bullet.record.BulletRecord) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.testng.annotations.Test)

Example 19 with BulletRecord

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

the class FrequentItemsSketchTest method testResetting.

@Test
public void testResetting() {
    FrequentItemsSketch sketch = new FrequentItemsSketch(ErrorType.NO_FALSE_NEGATIVES, 32, 32);
    IntStream.range(0, 10).forEach(i -> IntStream.range(0, 10).forEach(j -> sketch.update(String.valueOf(i))));
    IntStream.range(10, 100).forEach(i -> sketch.update("bar"));
    FrequentItemsSketch another = new FrequentItemsSketch(ErrorType.NO_FALSE_NEGATIVES, 32, 32);
    another.update("foo");
    another.update("bar");
    another.update("baz");
    sketch.union(another.serialize());
    Clip result = sketch.getResult("meta", ALL_METADATA);
    Map<String, Object> metadata = (Map<String, Object>) result.getMeta().asMap().get("meta");
    Assert.assertFalse((Boolean) metadata.get("isEst"));
    Assert.assertEquals(result.getRecords().size(), 13);
    Assert.assertEquals(sketch.getRecords(), result.getRecords());
    Assert.assertEquals(sketch.getMetadata("meta", ALL_METADATA).asMap(), result.getMeta().asMap());
    sketch.reset();
    result = sketch.getResult("meta", ALL_METADATA);
    metadata = (Map<String, Object>) result.getMeta().asMap().get("meta");
    Assert.assertEquals((String) metadata.get("family"), Family.FREQUENCY.getFamilyName());
    Assert.assertNull(metadata.get("size"));
    Assert.assertEquals(metadata.get("error"), 0L);
    Assert.assertEquals(metadata.get("n"), 0L);
    Assert.assertEquals(metadata.get("actives"), 0);
    Assert.assertFalse((Boolean) metadata.get("isEst"));
    List<BulletRecord> records = result.getRecords();
    Assert.assertEquals(records.size(), 0);
    Assert.assertEquals(sketch.getRecords(), result.getRecords());
    Assert.assertEquals(sketch.getMetadata("meta", ALL_METADATA).asMap(), result.getMeta().asMap());
}
Also used : IntStream(java.util.stream.IntStream) List(java.util.List) Assert(org.testng.Assert) BulletRecord(com.yahoo.bullet.record.BulletRecord) SketchesArgumentException(com.yahoo.sketches.SketchesArgumentException) Meta(com.yahoo.bullet.result.Meta) Map(java.util.Map) Test(org.testng.annotations.Test) HashMap(java.util.HashMap) ErrorType(com.yahoo.sketches.frequencies.ErrorType) Clip(com.yahoo.bullet.result.Clip) Family(com.yahoo.sketches.Family) Clip(com.yahoo.bullet.result.Clip) BulletRecord(com.yahoo.bullet.record.BulletRecord) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.testng.annotations.Test)

Example 20 with BulletRecord

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

the class FrequentItemsSketchTest method testSizeLimiting.

@Test
public void testSizeLimiting() {
    FrequentItemsSketch sketch = new FrequentItemsSketch(ErrorType.NO_FALSE_NEGATIVES, 32, 10);
    // For i from 1 to 13, update the sketch i times
    IntStream.range(1, 13).forEach(i -> IntStream.range(0, i).forEach(j -> sketch.update(String.valueOf(i))));
    Clip result = sketch.getResult("meta", ALL_METADATA);
    Map<String, Object> metadata = (Map<String, Object>) result.getMeta().asMap().get("meta");
    Assert.assertEquals(metadata.size(), 5);
    Assert.assertFalse((Boolean) metadata.get("isEst"));
    List<BulletRecord> records = result.getRecords();
    Assert.assertEquals(records.size(), 10);
    for (BulletRecord actual : records) {
        Assert.assertEquals(actual.fieldCount(), 2);
        Integer item = Integer.valueOf(actual.get(FrequentItemsSketch.ITEM_FIELD).toString());
        // 1, 2 had the lowest and since our size is 10, we should have not seen them
        Assert.assertTrue(item > 2 && item < 13);
        Assert.assertEquals(actual.get(FrequentItemsSketch.COUNT_FIELD), Long.valueOf(item));
    }
    Assert.assertEquals(sketch.getRecords(), result.getRecords());
    Assert.assertEquals(sketch.getMetadata("meta", ALL_METADATA).asMap(), result.getMeta().asMap());
}
Also used : IntStream(java.util.stream.IntStream) List(java.util.List) Assert(org.testng.Assert) BulletRecord(com.yahoo.bullet.record.BulletRecord) SketchesArgumentException(com.yahoo.sketches.SketchesArgumentException) Meta(com.yahoo.bullet.result.Meta) Map(java.util.Map) Test(org.testng.annotations.Test) HashMap(java.util.HashMap) ErrorType(com.yahoo.sketches.frequencies.ErrorType) Clip(com.yahoo.bullet.result.Clip) Family(com.yahoo.sketches.Family) Clip(com.yahoo.bullet.result.Clip) BulletRecord(com.yahoo.bullet.record.BulletRecord) Map(java.util.Map) HashMap(java.util.HashMap) 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