Search in sources :

Example 1 with BulletRecord

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()));
}
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 BulletRecord

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);
}
Also used : BulletRecord(com.yahoo.bullet.record.BulletRecord) Test(org.testng.annotations.Test)

Example 3 with BulletRecord

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);
}
Also used : BulletRecord(com.yahoo.bullet.record.BulletRecord) Test(org.testng.annotations.Test)

Example 4 with BulletRecord

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);
}
Also used : BulletRecord(com.yahoo.bullet.record.BulletRecord) Test(org.testng.annotations.Test)

Example 5 with BulletRecord

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

Aggregations

BulletRecord (com.yahoo.bullet.record.BulletRecord)210 Test (org.testng.annotations.Test)196 Tuple (org.apache.storm.tuple.Tuple)55 CountDistinctTest (com.yahoo.bullet.aggregations.CountDistinctTest)53 DistributionTest (com.yahoo.bullet.aggregations.DistributionTest)53 TopKTest (com.yahoo.bullet.aggregations.TopKTest)53 Clip (com.yahoo.bullet.result.Clip)53 HashMap (java.util.HashMap)53 Map (java.util.Map)53 BulletConfig (com.yahoo.bullet.common.BulletConfig)46 List (java.util.List)45 IntStream (java.util.stream.IntStream)45 Assert (org.testng.Assert)45 RecordBox (com.yahoo.bullet.result.RecordBox)43 Arrays.asList (java.util.Arrays.asList)40 Pair (org.apache.commons.lang3.tuple.Pair)40 AggregationUtils.makeAttributes (com.yahoo.bullet.parsing.AggregationUtils.makeAttributes)34 BulletError (com.yahoo.bullet.common.BulletError)33 Aggregation (com.yahoo.bullet.parsing.Aggregation)33 Concept (com.yahoo.bullet.result.Meta.Concept)33