use of com.yahoo.bullet.record.BulletRecord in project bullet-core by yahoo.
the class TopKTest method testResetting.
@Test
public void testResetting() {
TopK topK = makeTopK(asList("A", "B"), 64, 4);
IntStream.range(0, 60).mapToObj(i -> RecordBox.get().add("A", i % 3).getRecord()).forEach(topK::consume);
BulletRecord expectedA = RecordBox.get().add("A", "0").add("B", "null").add(TopK.DEFAULT_NEW_NAME, 20L).getRecord();
BulletRecord expectedB = RecordBox.get().add("A", "1").add("B", "null").add(TopK.DEFAULT_NEW_NAME, 20L).getRecord();
BulletRecord expectedC = RecordBox.get().add("A", "2").add("B", "null").add(TopK.DEFAULT_NEW_NAME, 20L).getRecord();
Clip result = topK.getResult();
List<BulletRecord> records = result.getRecords();
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());
topK.reset();
topK.consume(RecordBox.get().add("A", 0).getRecord());
topK.consume(RecordBox.get().add("A", 0).getRecord());
topK.consume(RecordBox.get().add("A", 1).getRecord());
result = topK.getResult();
records = result.getRecords();
Assert.assertEquals(records.size(), 2);
expectedA = RecordBox.get().add("A", "0").add("B", "null").add(TopK.DEFAULT_NEW_NAME, 2L).getRecord();
expectedB = RecordBox.get().add("A", "1").add("B", "null").add(TopK.DEFAULT_NEW_NAME, 1L).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 GroupDataSummarySetOperationsTest method testUnionRightNull.
@Test
public void testUnionRightNull() {
GroupDataSummarySetOperations operations = new GroupDataSummarySetOperations();
GroupDataSummary summary = new GroupDataSummary();
summary.setData(makeSampleGroupData(15, 0.1));
GroupDataSummary result = operations.union(summary, null);
BulletRecord actual = result.getData().getAsBulletRecord(emptyMap());
BulletRecord expected = RecordBox.get().add("fieldA", "foo").add("fieldB", "bar").add("sum", 15.0).add("min", 0.1).getRecord();
// In-place
Assert.assertTrue(summary == result);
Assert.assertTrue(actual.equals(expected));
}
use of com.yahoo.bullet.record.BulletRecord in project bullet-core by yahoo.
the class GroupDataSummaryTest method testSerialization.
@Test
public void testSerialization() {
List<String> groups = asList("foo", "bar", "baz");
List<GroupOperation.GroupOperationType> operations = asList(COUNT, MAX, MIN);
CachingGroupData data = new CachingGroupData(makeGroups(groups), makeMetrics(operations));
data.setCachedRecord(RecordBox.get().getRecord());
GroupDataSummary summary = new GroupDataSummary();
summary.update(data);
byte[] serialized = summary.toByteArray();
Assert.assertNotNull(serialized);
Memory memory = new NativeMemory(serialized);
byte initializedByte = memory.getByte(GroupDataSummary.INITIALIZED_POSITION);
int length = memory.getInt(GroupDataSummary.SIZE_POSITION);
byte[] dataSerialized = new byte[length];
memory.getByteArray(GroupDataSummary.DATA_POSITION, dataSerialized, 0, length);
CachingGroupData deserialized = SerializerDeserializer.fromBytes(dataSerialized);
Assert.assertTrue(initializedByte == 1);
Assert.assertTrue(length > 0);
Assert.assertNotNull(deserialized);
Assert.assertNull(deserialized.getCachedRecord());
BulletRecord actual = deserialized.getAsBulletRecord(emptyMap());
BulletRecord expected = RecordBox.get().add("field_0", "foo").add("field_1", "bar").add("field_2", "baz").add("COUNT_metric_0", 1).addNull("MAX_metric_1").addNull("MIN_metric_2").getRecord();
Assert.assertTrue(actual.equals(expected));
}
use of com.yahoo.bullet.record.BulletRecord in project bullet-core by yahoo.
the class GroupDataSummaryTest method testMergeValidSummaries.
@Test
public void testMergeValidSummaries() {
List<String> groups = asList("foo", "bar");
List<GroupOperation.GroupOperationType> operations = asList(SUM, MIN);
CachingGroupData data = new CachingGroupData(makeGroups(groups), makeMetrics(operations));
GroupDataSummary summaryA = new GroupDataSummary();
GroupDataSummary summaryB = new GroupDataSummary();
BulletRecord record = makeRecord(groups, operations, 0);
data.setCachedRecord(record);
summaryA.update(data);
record = makeRecord(groups, operations, 15);
data.setCachedRecord(record);
summaryA.update(data);
record = makeRecord(groups, operations, -10);
data.setCachedRecord(record);
summaryB.update(data);
GroupDataSummary merged = GroupDataSummary.mergeInPlace(summaryA, summaryB);
Assert.assertNotNull(merged);
GroupData mergedData = merged.getData();
GroupData summaryAData = summaryA.getData();
GroupData summaryBData = summaryB.getData();
Assert.assertNotNull(mergedData);
// They are the same object
Assert.assertTrue(mergedData == summaryAData);
Assert.assertTrue(mergedData.groupFields == summaryAData.groupFields);
Assert.assertTrue(mergedData.metrics == summaryAData.metrics);
// They are different objects
Assert.assertFalse(mergedData == summaryBData);
BulletRecord actual = mergedData.getAsBulletRecord(emptyMap());
BulletRecord expected = RecordBox.get().add("field_0", "foo").add("field_1", "bar").add("SUM_metric_0", 5.0).add("MIN_metric_1", -13.0).getRecord();
Assert.assertTrue(actual.equals(expected));
}
use of com.yahoo.bullet.record.BulletRecord in project bullet-core by yahoo.
the class CountDistinctTest method testMultipleFieldsCountDistinct.
@Test
public void testMultipleFieldsCountDistinct() {
BulletConfig config = makeConfiguration(4, 512);
CountDistinct countDistinct = makeCountDistinct(config, makeAttributes("myCount"), asList("fieldA", "fieldB"));
IntStream.range(0, 256).mapToObj(i -> RecordBox.get().add("fieldA", i).add("fieldB", 255 - i).getRecord()).forEach(countDistinct::consume);
IntStream.range(0, 256).mapToObj(i -> RecordBox.get().add("fieldA", i).add("fieldB", 255 - i).getRecord()).forEach(countDistinct::consume);
Clip clip = countDistinct.getResult();
Assert.assertEquals(clip.getRecords().size(), 1);
BulletRecord actual = clip.getRecords().get(0);
BulletRecord expected = RecordBox.get().add("myCount", 256.0).getRecord();
Assert.assertEquals(actual, expected);
Assert.assertEquals(countDistinct.getRecords(), clip.getRecords());
Assert.assertEquals(countDistinct.getMetadata().asMap(), countDistinct.getMetadata().asMap());
}
Aggregations