use of com.yahoo.bullet.record.BulletRecord in project bullet-core by yahoo.
the class GroupDataTest method testNoRecordAvg.
@Test
public void testNoRecordAvg() {
GroupData data = make(new GroupOperation(GroupOperation.GroupOperationType.AVG, "someField", "avg"));
// AVG will return null if no records are observed
BulletRecord expected = RecordBox.get().addNull("avg").getRecord();
Assert.assertEquals(data.getMetricsAsBulletRecord(), expected);
}
use of com.yahoo.bullet.record.BulletRecord in project bullet-core by yahoo.
the class GroupDataTest method testMergingMetric.
@Test
public void testMergingMetric() {
GroupData data = make(new GroupOperation(GroupOperation.GroupOperationType.COUNT, "shouldBeIgnored", "myCount"), new GroupOperation(GroupOperation.GroupOperationType.MIN, "groupField", "myMin"), new GroupOperation(GroupOperation.GroupOperationType.MAX, "groupField", "myMax"), new GroupOperation(GroupOperation.GroupOperationType.SUM, "groupField", "mySum"), new GroupOperation(GroupOperation.GroupOperationType.AVG, "groupField", "myAvg"));
asList(0.0, -8.8, 51.0).stream().map(x -> RecordBox.get().add("groupField", x).getRecord()).forEach(data::consume);
GroupData another = make(new GroupOperation(GroupOperation.GroupOperationType.COUNT, "alsoIgnored", "myCount"), new GroupOperation(GroupOperation.GroupOperationType.MIN, "groupField", "myMin"), new GroupOperation(GroupOperation.GroupOperationType.MAX, "groupField", "myMax"), new GroupOperation(GroupOperation.GroupOperationType.SUM, "groupField", "mySum"), new GroupOperation(GroupOperation.GroupOperationType.AVG, "groupField", "myAvg"));
asList(1.1, 4.4, -44.0, 12345.67, 3.3).stream().map(x -> RecordBox.get().add("groupField", x).getRecord()).forEach(data::consume);
byte[] serialized = SerializerDeserializer.toBytes(another);
data.combine(serialized);
BulletRecord expected = RecordBox.get().add("myCount", 8L).add("myMin", -44.0).add("myMax", 12345.67).add("mySum", 12352.67).add("myAvg", 1544.08375).getRecord();
Assert.assertTrue(expected.equals(data.getMetricsAsBulletRecord()));
}
use of com.yahoo.bullet.record.BulletRecord in project bullet-core by yahoo.
the class GroupDataTest method testNoRecordMin.
@Test
public void testNoRecordMin() {
GroupData data = make(new GroupOperation(GroupOperation.GroupOperationType.MIN, null, "min"));
// MIN will return null if no records are observed
BulletRecord expected = RecordBox.get().addNull("min").getRecord();
Assert.assertEquals(data.getMetricsAsBulletRecord(), expected);
}
use of com.yahoo.bullet.record.BulletRecord in project bullet-core by yahoo.
the class GroupDataTest method testGroupFieldsInData.
@Test
public void testGroupFieldsInData() {
Map<String, String> fields = new HashMap<>();
fields.put("fieldA", "foo");
fields.put("fieldB", "bar");
GroupData data = make(fields, new GroupOperation(GroupOperation.GroupOperationType.SUM, "someField", "sum"));
BulletRecord expectedUnmapped = RecordBox.get().addNull("sum").getRecord();
Map<String, String> fieldMapping = new HashMap<>();
fieldMapping.put("fieldA", "newFieldNameA");
fieldMapping.put("fieldB", "fieldB");
BulletRecord expected = RecordBox.get().add("newFieldNameA", "foo").add("fieldB", "bar").addNull("sum").getRecord();
Assert.assertTrue(data.getMetricsAsBulletRecord().equals(expectedUnmapped));
Assert.assertTrue(data.getAsBulletRecord(fieldMapping).equals(expected));
data.consume(RecordBox.get().add("someField", 21.0).getRecord());
data.consume(RecordBox.get().add("someField", 21.0).getRecord());
data.consume(RecordBox.get().addNull("someField").getRecord());
expected = RecordBox.get().add("foo", "foo").add("bar", "bar").add("sum", 42.0).getRecord();
Assert.assertTrue(data.getAsBulletRecord(fields).equals(expected));
}
use of com.yahoo.bullet.record.BulletRecord in project bullet-core by yahoo.
the class GroupDataTest method testMergingRawMetricFail.
@Test
public void testMergingRawMetricFail() {
GroupData data = make(new GroupOperation(GroupOperation.GroupOperationType.COUNT, null, null));
BulletRecord someRecord = RecordBox.get().add("foo", 1).getRecord();
IntStream.range(0, 10).forEach(i -> data.consume(someRecord));
// Not a serialized GroupData
data.combine(String.valueOf(242).getBytes());
// Unchanged count
BulletRecord expected = RecordBox.get().add(GroupOperation.GroupOperationType.COUNT.getName(), 10L).getRecord();
Assert.assertEquals(data.getMetricsAsBulletRecord(), expected);
}
Aggregations