use of com.yahoo.bullet.record.BulletRecord in project bullet-core by yahoo.
the class GroupDataTest method testGroupMultipleFields.
@Test
public void testGroupMultipleFields() {
GroupData data = make(new GroupOperation(GroupOperation.GroupOperationType.COUNT, "shouldBeIgnored", "myCount"), new GroupOperation(GroupOperation.GroupOperationType.MIN, "minField", "myMin"), new GroupOperation(GroupOperation.GroupOperationType.MIN, "groupField", "minGroupField"), new GroupOperation(GroupOperation.GroupOperationType.MAX, "maxField", "myMax"), new GroupOperation(GroupOperation.GroupOperationType.MAX, "groupField", "maxGroupField"), new GroupOperation(GroupOperation.GroupOperationType.SUM, "groupField", "sumGroupField"));
List<Double> minColumnValues = asList(0.0, -8.8, 51.0);
List<Double> maxColumnValues = asList(4.4, 88.51, -8.44);
List<Double> groupColumnValues = asList(123.45, -884451.8851, 3.14);
List<BulletRecord> records = new ArrayList<>();
for (int i = 0; i < minColumnValues.size(); i++) {
RecordBox recordBox = RecordBox.get();
recordBox.add("minField", minColumnValues.get(i));
recordBox.add("maxField", maxColumnValues.get(i));
recordBox.add("groupField", groupColumnValues.get(i));
records.add(recordBox.getRecord());
}
records.stream().forEach(data::consume);
BulletRecord expected = RecordBox.get().add("myCount", 3L).add("myMin", -8.8).add("minGroupField", -884451.8851).add("myMax", 88.51).add("maxGroupField", 123.45).add("sumGroupField", -884325.2951).getRecord();
Assert.assertTrue(expected.equals(data.getMetricsAsBulletRecord()));
}
use of com.yahoo.bullet.record.BulletRecord in project bullet-core by yahoo.
the class GroupDataTest method testNullRecordMin.
@Test
public void testNullRecordMin() {
GroupData data = make(new GroupOperation(GroupOperation.GroupOperationType.MIN, null, "min"));
data.consume(RecordBox.get().add("foo", "bar").getRecord());
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 testNoRecordCount.
@Test
public void testNoRecordCount() {
GroupData data = make(new GroupOperation(GroupOperation.GroupOperationType.COUNT, null, "count"));
// Count should be 0 if there was no data presented.
BulletRecord expected = RecordBox.get().add("count", 0L).getRecord();
Assert.assertEquals(data.getMetricsAsBulletRecord(), expected);
}
use of com.yahoo.bullet.record.BulletRecord in project bullet-core by yahoo.
the class GroupDataTest method testIgnoreNullsAvg.
@Test
public void testIgnoreNullsAvg() {
GroupData data = make(new GroupOperation(GroupOperation.GroupOperationType.AVG, "someField", "foo"));
BulletRecord expected = RecordBox.get().addNull("foo").getRecord();
Assert.assertEquals(data.getMetricsAsBulletRecord(), expected);
data.consume(RecordBox.get().addNull("someField").getRecord());
expected = RecordBox.get().addNull("foo").getRecord();
Assert.assertEquals(data.getMetricsAsBulletRecord(), expected);
data.consume(RecordBox.get().add("someField", 8.8).getRecord());
data.consume(RecordBox.get().add("someField", 51.4).getRecord());
expected = RecordBox.get().add("foo", 30.1).getRecord();
Assert.assertEquals(data.getMetricsAsBulletRecord(), expected);
data.consume(RecordBox.get().addNull("someField").getRecord());
expected = RecordBox.get().add("foo", 30.1).getRecord();
Assert.assertEquals(data.getMetricsAsBulletRecord(), expected);
data.consume(RecordBox.get().add("someField", -4.4).getRecord());
expected = RecordBox.get().add("foo", 18.6).getRecord();
Assert.assertEquals(data.getMetricsAsBulletRecord(), expected);
}
use of com.yahoo.bullet.record.BulletRecord in project bullet-core by yahoo.
the class GroupDataTest method testCastingNonNumericCastableMetrics.
@Test
public void testCastingNonNumericCastableMetrics() {
Map<String, String> fields = new HashMap<>();
fields.put("fieldA", "foo");
fields.put("fieldB", "bar");
GroupData data = make(fields, new GroupOperation(GroupOperation.GroupOperationType.SUM, "mapA.someField", "sum"), new GroupOperation(GroupOperation.GroupOperationType.AVG, "otherField", "avg"));
BulletRecord record;
record = RecordBox.get().addMap("mapA", Pair.of("someField", "48.2")).add("otherField", "17").getRecord();
data.consume(record);
record = RecordBox.get().addMap("mapA", Pair.of("someField", "35.8")).add("otherField", "67").getRecord();
data.consume(record);
BulletRecord expected = RecordBox.get().add("fieldA", "foo").add("fieldB", "bar").add("sum", 84.0).add("avg", 42.0).getRecord();
BulletRecord actual = data.getAsBulletRecord();
Assert.assertTrue(actual.equals(expected));
}
Aggregations