Search in sources :

Example 1 with RecordBox

use of com.yahoo.bullet.result.RecordBox 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()));
}
Also used : RecordBox(com.yahoo.bullet.result.RecordBox) BulletRecord(com.yahoo.bullet.record.BulletRecord) ArrayList(java.util.ArrayList) Test(org.testng.annotations.Test)

Example 2 with RecordBox

use of com.yahoo.bullet.result.RecordBox in project bullet-core by yahoo.

the class FilterOperationsTest method testComparisonBooleanMap.

@Test
public void testComparisonBooleanMap() {
    FilterClause clause = getFieldFilter("filter_map.is_fake_event", EQUALS, "true");
    // "null" is not true
    Assert.assertFalse(FilterOperations.perform(RecordBox.get().getRecord(), clause));
    RecordBox box = RecordBox.get();
    Assert.assertFalse(FilterOperations.perform(box.getRecord(), clause));
    box.addMap("filter_map", Pair.of("is_fake_event", true));
    Assert.assertTrue(FilterOperations.perform(box.getRecord(), clause));
    box.addMap("filter_map", Pair.of("is_fake_event", false));
    Assert.assertFalse(FilterOperations.perform(box.getRecord(), clause));
}
Also used : RecordBox(com.yahoo.bullet.result.RecordBox) FilterClause(com.yahoo.bullet.parsing.FilterClause) Test(org.testng.annotations.Test)

Example 3 with RecordBox

use of com.yahoo.bullet.result.RecordBox in project bullet-core by yahoo.

the class FilterOperationsTest method testComparisonUncastable.

@Test
public void testComparisonUncastable() {
    FilterClause clause = getFieldFilter("unreal", EQUALS, "1.23", "4.56");
    RecordBox box = RecordBox.get().add("unreal", 123L);
    // Trying to cast
    Assert.assertFalse(FilterOperations.perform(box.getRecord(), clause));
}
Also used : RecordBox(com.yahoo.bullet.result.RecordBox) FilterClause(com.yahoo.bullet.parsing.FilterClause) Test(org.testng.annotations.Test)

Example 4 with RecordBox

use of com.yahoo.bullet.result.RecordBox in project bullet-core by yahoo.

the class ProjectionOperationsTest method testProjection.

@Test
public void testProjection() {
    Projection projection = makeProjection("map_field.foo", "bar");
    RecordBox box = RecordBox.get().addMap("map_field", Pair.of("foo", "baz"));
    BulletRecord actual = ProjectionOperations.project(box.getRecord(), projection);
    BulletRecord expected = RecordBox.get().add("bar", "baz").getRecord();
    Assert.assertEquals(actual, expected);
}
Also used : RecordBox(com.yahoo.bullet.result.RecordBox) BulletRecord(com.yahoo.bullet.record.BulletRecord) ProjectionUtils.makeProjection(com.yahoo.bullet.parsing.ProjectionUtils.makeProjection) Projection(com.yahoo.bullet.parsing.Projection) Test(org.testng.annotations.Test)

Example 5 with RecordBox

use of com.yahoo.bullet.result.RecordBox in project bullet-core by yahoo.

the class GroupDataSummaryTest method makeRecord.

private static BulletRecord makeRecord(List<String> fields, List<GroupOperation.GroupOperationType> operations, int base) {
    RecordBox box = RecordBox.get();
    for (int i = 0; i < fields.size(); i++) {
        box.add("field_" + i, fields.get(i));
    }
    for (int i = 0; i < operations.size(); i++) {
        String key = "metric_" + i;
        GroupOperation.GroupOperationType type = operations.get(i);
        Number number = makeNumber(type, base, i, operations.size());
        if (number != null) {
            box.add(key, number);
        }
    }
    return box.getRecord();
}
Also used : RecordBox(com.yahoo.bullet.result.RecordBox)

Aggregations

RecordBox (com.yahoo.bullet.result.RecordBox)8 Test (org.testng.annotations.Test)7 FilterClause (com.yahoo.bullet.parsing.FilterClause)3 BulletRecord (com.yahoo.bullet.record.BulletRecord)3 Projection (com.yahoo.bullet.parsing.Projection)2 ProjectionUtils.makeProjection (com.yahoo.bullet.parsing.ProjectionUtils.makeProjection)2 ArrayList (java.util.ArrayList)1