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);
}
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);
}
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());
}
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());
}
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());
}
Aggregations