use of com.yahoo.bullet.record.BulletRecord in project bullet-core by yahoo.
the class RawTest method testWritingBadRecord.
@Test
public void testWritingBadRecord() {
BulletRecord mocked = new NoSerDeBulletRecord();
Raw raw = makeRaw(1);
raw.consume(mocked);
Assert.assertNull(raw.getData());
}
use of com.yahoo.bullet.record.BulletRecord in project bullet-core by yahoo.
the class RawTest method testLimitZero.
@Test
public void testLimitZero() {
Raw raw = makeRaw(0);
List<BulletRecord> aggregate = raw.getResult().getRecords();
Assert.assertTrue(raw.isClosed());
Assert.assertEquals(aggregate.size(), 0);
BulletRecord record = RecordBox.get().add("foo", "bar").getRecord();
raw.consume(record);
Assert.assertTrue(raw.isClosed());
Assert.assertNull(raw.getData());
Assert.assertEquals(raw.getResult().getRecords().size(), 0);
}
use of com.yahoo.bullet.record.BulletRecord in project bullet-core by yahoo.
the class TopKTest method testExactTopKThreshold.
@Test
public void testExactTopKThreshold() {
TopK topK = makeTopK(ErrorType.NO_FALSE_POSITIVES, asList("A", "B"), "cnt", 64, 3, 25L);
IntStream.range(0, 20).mapToObj(i -> RecordBox.get().add("A", i).getRecord()).forEach(topK::consume);
IntStream.range(0, 25).mapToObj(i -> RecordBox.get().add("A", 108).getRecord()).forEach(topK::consume);
IntStream.range(0, 24).mapToObj(i -> RecordBox.get().add("A", "foo").add("B", "bar").getRecord()).forEach(topK::consume);
IntStream.range(0, 100).mapToObj(i -> RecordBox.get().add("A", 42L).getRecord()).forEach(topK::consume);
Clip result = topK.getResult();
List<BulletRecord> records = result.getRecords();
Assert.assertEquals(records.size(), 2);
BulletRecord expectedA = RecordBox.get().add("A", "42").add("B", "null").add("cnt", 100L).getRecord();
BulletRecord expectedB = RecordBox.get().add("A", "108").add("B", "null").add("cnt", 25L).getRecord();
Assert.assertEquals(records.get(0), expectedA);
Assert.assertEquals(records.get(1), expectedB);
IntStream.range(0, 11).mapToObj(i -> RecordBox.get().add("A", "foo").add("B", "bar").getRecord()).forEach(topK::consume);
result = topK.getResult();
records = result.getRecords();
Assert.assertEquals(records.size(), 3);
expectedA = RecordBox.get().add("A", "42").add("B", "null").add("cnt", 100L).getRecord();
expectedB = RecordBox.get().add("A", "foo").add("B", "bar").add("cnt", 35L).getRecord();
BulletRecord expectedC = RecordBox.get().add("A", "108").add("B", "null").add("cnt", 25L).getRecord();
Assert.assertEquals(records.get(0), expectedA);
Assert.assertEquals(records.get(1), expectedB);
Assert.assertEquals(records.get(2), expectedC);
Assert.assertEquals(topK.getRecords(), records);
Assert.assertEquals(topK.getMetadata().asMap(), result.getMeta().asMap());
}
use of com.yahoo.bullet.record.BulletRecord in project bullet-core by yahoo.
the class TopKTest method testExactTopKSizeLimiting.
@Test
public void testExactTopKSizeLimiting() {
TopK topK = makeTopK(ErrorType.NO_FALSE_POSITIVES, singletonList("A"), "cnt", 64, 2, null);
IntStream.range(0, 20).mapToObj(i -> RecordBox.get().add("A", i).getRecord()).forEach(topK::consume);
IntStream.range(0, 20).mapToObj(i -> RecordBox.get().add("A", 108.1).getRecord()).forEach(topK::consume);
IntStream.range(0, 100).mapToObj(i -> RecordBox.get().add("A", 42L).getRecord()).forEach(topK::consume);
Clip result = topK.getResult();
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(), 2);
BulletRecord expectedA = RecordBox.get().add("A", "42").add("cnt", 100L).getRecord();
BulletRecord expectedB = RecordBox.get().add("A", "108.1").add("cnt", 20L).getRecord();
Assert.assertEquals(records.get(0), expectedA);
Assert.assertEquals(records.get(1), expectedB);
Assert.assertEquals(topK.getRecords(), records);
Assert.assertEquals(topK.getMetadata().asMap(), result.getMeta().asMap());
}
use of com.yahoo.bullet.record.BulletRecord in project bullet-core by yahoo.
the class TopKTest method testBadMaxMapEntries.
@Test
public void testBadMaxMapEntries() {
TopK topK = makeTopK(makeConfiguration(ErrorType.NO_FALSE_NEGATIVES, -1), null, singletonMap("A", "foo"), BulletConfig.DEFAULT_TOP_K_AGGREGATION_SKETCH_ENTRIES, null);
int uniqueGroups = BulletConfig.DEFAULT_TOP_K_AGGREGATION_SKETCH_ENTRIES / 4;
IntStream.range(0, uniqueGroups).mapToObj(i -> RecordBox.get().add("A", i).getRecord()).forEach(topK::consume);
Clip result = topK.getResult();
Assert.assertNull(result.getMeta().asMap().get("meta"));
List<BulletRecord> records = result.getRecords();
Assert.assertEquals(records.size(), uniqueGroups);
for (BulletRecord actual : records) {
Assert.assertEquals(actual.fieldCount(), 2);
int fieldA = Integer.valueOf(actual.get("foo").toString());
Assert.assertTrue(fieldA < uniqueGroups);
Assert.assertEquals(actual.get(TopK.DEFAULT_NEW_NAME), 1L);
}
Assert.assertEquals(topK.getRecords(), records);
Assert.assertEquals(topK.getMetadata().asMap(), result.getMeta().asMap());
// Not a power of 2
TopK another = makeTopK(makeConfiguration(ErrorType.NO_FALSE_NEGATIVES, 5), null, singletonMap("A", "foo"), BulletConfig.DEFAULT_TOP_K_AGGREGATION_SKETCH_ENTRIES, null);
IntStream.range(0, uniqueGroups).mapToObj(i -> RecordBox.get().add("A", i).getRecord()).forEach(another::consume);
result = another.getResult();
Assert.assertNull(result.getMeta().asMap().get("meta"));
records = result.getRecords();
Assert.assertEquals(records.size(), uniqueGroups);
Assert.assertEquals(another.getRecords(), records);
Assert.assertEquals(another.getMetadata().asMap(), result.getMeta().asMap());
}
Aggregations