Search in sources :

Example 11 with BulletRecord

use of com.yahoo.bullet.record.BulletRecord in project bullet-core by yahoo.

the class GroupDataTest method testNoRecordSum.

@Test
public void testNoRecordSum() {
    GroupData data = make(new GroupOperation(GroupOperation.GroupOperationType.SUM, null, "sum"));
    // SUM will return null if no records are observed
    BulletRecord expected = RecordBox.get().addNull("sum").getRecord();
    Assert.assertEquals(data.getMetricsAsBulletRecord(), expected);
}
Also used : BulletRecord(com.yahoo.bullet.record.BulletRecord) Test(org.testng.annotations.Test)

Example 12 with BulletRecord

use of com.yahoo.bullet.record.BulletRecord in project bullet-core by yahoo.

the class GroupDataTest method testNonNumericSum.

@Test
public void testNonNumericSum() {
    GroupData data = make(new GroupOperation(GroupOperation.GroupOperationType.SUM, "someField", "foo"));
    BulletRecord expected = RecordBox.get().addNull("foo").getRecord();
    Assert.assertEquals(data.getMetricsAsBulletRecord(), expected);
    data.consume(RecordBox.get().add("someField", "nonNumericValue").getRecord());
    expected = RecordBox.get().addNull("foo").getRecord();
    Assert.assertEquals(data.getMetricsAsBulletRecord(), expected);
    data.consume(RecordBox.get().add("someField", 8.8).getRecord());
    expected = RecordBox.get().add("foo", 8.8).getRecord();
    Assert.assertEquals(data.getMetricsAsBulletRecord(), expected);
    data.consume(RecordBox.get().add("someField", "nonNumericValue").getRecord());
    expected = RecordBox.get().add("foo", 8.8).getRecord();
    Assert.assertEquals(data.getMetricsAsBulletRecord(), expected);
    data.consume(RecordBox.get().add("someField", 51.4).getRecord());
    expected = RecordBox.get().add("foo", 60.2).getRecord();
    Assert.assertEquals(data.getMetricsAsBulletRecord(), expected);
}
Also used : BulletRecord(com.yahoo.bullet.record.BulletRecord) Test(org.testng.annotations.Test)

Example 13 with BulletRecord

use of com.yahoo.bullet.record.BulletRecord in project bullet-core by yahoo.

the class GroupDataTest method testMergingSupportedAndUnSupportedOperation.

@Test
public void testMergingSupportedAndUnSupportedOperation() {
    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));
    GroupData another = make(new GroupOperation(GroupOperation.GroupOperationType.AVG, "foo", "bar"));
    IntStream.range(0, 21).forEach(i -> another.consume(someRecord));
    byte[] serialized = SerializerDeserializer.toBytes(another);
    // This should combine since we only merge known GroupOperations from the other GroupData
    data.combine(serialized);
    // AVG should not have influenced other counts.
    BulletRecord expected = RecordBox.get().add(GroupOperation.GroupOperationType.COUNT.getName(), 10L).getRecord();
    Assert.assertEquals(data.getMetricsAsBulletRecord(), expected);
}
Also used : BulletRecord(com.yahoo.bullet.record.BulletRecord) Test(org.testng.annotations.Test)

Example 14 with BulletRecord

use of com.yahoo.bullet.record.BulletRecord in project bullet-core by yahoo.

the class GroupDataTest method testNoRecordMax.

@Test
public void testNoRecordMax() {
    GroupData data = make(new GroupOperation(GroupOperation.GroupOperationType.MAX, null, "max"));
    // MAX will return null if no records are observed
    BulletRecord expected = RecordBox.get().addNull("max").getRecord();
    Assert.assertEquals(data.getMetricsAsBulletRecord(), expected);
}
Also used : BulletRecord(com.yahoo.bullet.record.BulletRecord) Test(org.testng.annotations.Test)

Example 15 with BulletRecord

use of com.yahoo.bullet.record.BulletRecord in project bullet-core by yahoo.

the class GroupDataTest method testMultiMin.

@Test
public void testMultiMin() {
    GroupData data = make(new GroupOperation(GroupOperation.GroupOperationType.MIN, "someField", "foo"));
    List<Double> numbers = asList(0.0, 8.8, -88.0, 51.0, 4.0, -4.0, 1234567.89, -51.0);
    numbers.stream().map(x -> RecordBox.get().add("someField", x).getRecord()).forEach(data::consume);
    BulletRecord expected = RecordBox.get().add("foo", -88.0).getRecord();
    Assert.assertEquals(data.getMetricsAsBulletRecord(), expected);
}
Also used : IntStream(java.util.stream.IntStream) BulletRecord(com.yahoo.bullet.record.BulletRecord) SerializerDeserializer(com.yahoo.bullet.common.SerializerDeserializer) Test(org.testng.annotations.Test) HashMap(java.util.HashMap) RecordBox(com.yahoo.bullet.result.RecordBox) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) List(java.util.List) Pair(org.apache.commons.lang3.tuple.Pair) Assert(org.testng.Assert) Arrays.asList(java.util.Arrays.asList) BulletConfig(com.yahoo.bullet.common.BulletConfig) Map(java.util.Map) Collections(java.util.Collections) BulletRecord(com.yahoo.bullet.record.BulletRecord) 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