Search in sources :

Example 16 with GroupOperation

use of com.yahoo.bullet.querying.aggregations.grouping.GroupOperation in project bullet-core by yahoo.

the class GroupAllStrategyTest method testMin.

@Test
public void testMin() {
    GroupAllStrategy strategy = makeGroupAll(new GroupOperation(GroupOperation.GroupOperationType.MIN, "someField", "min"));
    Assert.assertNotNull(strategy.getData());
    strategy.consume(RecordBox.get().addNull("someField").getRecord());
    BulletRecord expected = RecordBox.get().addNull("min").getRecord();
    Assert.assertEquals(strategy.getResult().getRecords().get(0), expected);
    strategy.consume(RecordBox.get().add("someField", -4.8).getRecord());
    strategy.consume(RecordBox.get().add("someField", -8.8).getRecord());
    strategy.consume(RecordBox.get().add("someField", 51.44).getRecord());
    expected = RecordBox.get().add("min", -8.8).getRecord();
    Assert.assertEquals(strategy.getResult().getRecords().get(0), expected);
    strategy.consume(RecordBox.get().addNull("someField").getRecord());
    expected = RecordBox.get().add("min", -8.8).getRecord();
    Assert.assertEquals(strategy.getResult().getRecords().get(0), expected);
    strategy.consume(RecordBox.get().add("someField", -51.44).getRecord());
    expected = RecordBox.get().add("min", -51.44).getRecord();
    Assert.assertEquals(strategy.getResult().getRecords().get(0), expected);
    Assert.assertEquals(strategy.getResult().getRecords().size(), 1);
    Assert.assertEquals(strategy.getRecords(), strategy.getResult().getRecords());
    Assert.assertEquals(strategy.getMetadata().asMap(), strategy.getResult().getMeta().asMap());
}
Also used : BulletRecord(com.yahoo.bullet.record.BulletRecord) GroupOperation(com.yahoo.bullet.querying.aggregations.grouping.GroupOperation) Test(org.testng.annotations.Test)

Example 17 with GroupOperation

use of com.yahoo.bullet.querying.aggregations.grouping.GroupOperation in project bullet-core by yahoo.

the class GroupAllStrategyTest method testCombiningMetrics.

@Test
public void testCombiningMetrics() {
    List<GroupOperation> operations = asList(new GroupOperation(GroupOperation.GroupOperationType.COUNT, null, "myCount"), new GroupOperation(GroupOperation.GroupOperationType.MIN, "minField", "myMin"), new GroupOperation(GroupOperation.GroupOperationType.AVG, "groupField", "groupAvg"), new GroupOperation(GroupOperation.GroupOperationType.MIN, "groupField", "groupMin"), new GroupOperation(GroupOperation.GroupOperationType.SUM, "groupField", "groupSum"));
    GroupAllStrategy strategy = makeGroupAll(operations);
    strategy.consume(RecordBox.get().add("minField", -8.8).add("groupField", 3.14).getRecord());
    strategy.consume(RecordBox.get().add("minField", 0.0).addNull("groupField").getRecord());
    strategy.consume(RecordBox.get().add("minField", 51.44).add("groupField", -4.88).getRecord());
    GroupAllStrategy another = makeGroupAll(operations);
    another.consume(RecordBox.get().add("minField", -8.8).add("groupField", 12345.67).getRecord());
    another.consume(RecordBox.get().addNull("minField").add("groupField", 2.718).getRecord());
    another.consume(RecordBox.get().add("minField", -51.0).addNull("groupField").getRecord());
    another.consume(RecordBox.get().add("minField", 0).add("groupField", 1).getRecord());
    another.consume(RecordBox.get().add("minField", 44.8).add("groupField", -51.44).getRecord());
    byte[] serialized = another.getData();
    strategy.combine(serialized);
    Assert.assertNotNull(strategy.getData());
    List<BulletRecord> aggregate = strategy.getResult().getRecords();
    Assert.assertEquals(aggregate.size(), 1);
    BulletRecord actual = aggregate.get(0);
    BulletRecord expected = RecordBox.get().add("myCount", 8L).add("myMin", -51.0).add("groupAvg", 2049.368).add("groupMin", -51.44).add("groupSum", 12296.208).getRecord();
    Assert.assertTrue(actual.equals(expected));
    Assert.assertEquals(strategy.getRecords(), aggregate);
    Assert.assertEquals(strategy.getMetadata().asMap(), strategy.getResult().getMeta().asMap());
}
Also used : BulletRecord(com.yahoo.bullet.record.BulletRecord) GroupOperation(com.yahoo.bullet.querying.aggregations.grouping.GroupOperation) Test(org.testng.annotations.Test)

Example 18 with GroupOperation

use of com.yahoo.bullet.querying.aggregations.grouping.GroupOperation in project bullet-core by yahoo.

the class GroupAllStrategyTest method testNoRecordCount.

@Test
public void testNoRecordCount() {
    GroupAllStrategy strategy = makeGroupAll(new GroupOperation(GroupOperation.GroupOperationType.COUNT, null, "count"));
    Assert.assertNotNull(strategy.getData());
    List<BulletRecord> aggregate = strategy.getResult().getRecords();
    Assert.assertEquals(aggregate.size(), 1);
    BulletRecord actual = aggregate.get(0);
    BulletRecord expected = RecordBox.get().add("count", 0L).getRecord();
    Assert.assertEquals(actual, expected);
    Assert.assertEquals(strategy.getRecords(), aggregate);
    Assert.assertEquals(strategy.getMetadata().asMap(), strategy.getResult().getMeta().asMap());
}
Also used : BulletRecord(com.yahoo.bullet.record.BulletRecord) GroupOperation(com.yahoo.bullet.querying.aggregations.grouping.GroupOperation) Test(org.testng.annotations.Test)

Example 19 with GroupOperation

use of com.yahoo.bullet.querying.aggregations.grouping.GroupOperation in project bullet-core by yahoo.

the class GroupAllStrategyTest method testCounting.

@Test
public void testCounting() {
    GroupAllStrategy strategy = makeGroupAll(new GroupOperation(GroupOperation.GroupOperationType.COUNT, null, "count"));
    BulletRecord someRecord = RecordBox.get().add("foo", 1L).getRecord();
    IntStream.range(0, 10).forEach(i -> strategy.consume(someRecord));
    Assert.assertNotNull(strategy.getData());
    List<BulletRecord> aggregate = strategy.getResult().getRecords();
    Assert.assertEquals(aggregate.size(), 1);
    BulletRecord actual = aggregate.get(0);
    BulletRecord expected = RecordBox.get().add("count", 10L).getRecord();
    Assert.assertEquals(actual, expected);
    Assert.assertEquals(strategy.getRecords(), aggregate);
    Assert.assertEquals(strategy.getMetadata().asMap(), strategy.getResult().getMeta().asMap());
}
Also used : BulletRecord(com.yahoo.bullet.record.BulletRecord) GroupOperation(com.yahoo.bullet.querying.aggregations.grouping.GroupOperation) Test(org.testng.annotations.Test)

Example 20 with GroupOperation

use of com.yahoo.bullet.querying.aggregations.grouping.GroupOperation in project bullet-core by yahoo.

the class GroupAllStrategyTest method testAvg.

@Test
public void testAvg() {
    GroupAllStrategy strategy = makeGroupAll(new GroupOperation(GroupOperation.GroupOperationType.AVG, "someField", "avg"));
    Assert.assertNotNull(strategy.getData());
    strategy.consume(RecordBox.get().addNull("someField").getRecord());
    BulletRecord expected = RecordBox.get().addNull("avg").getRecord();
    Assert.assertEquals(strategy.getResult().getRecords().get(0), expected);
    strategy.consume(RecordBox.get().add("someField", -4.8).getRecord());
    strategy.consume(RecordBox.get().add("someField", -8).getRecord());
    strategy.consume(RecordBox.get().add("someField", 51.44).getRecord());
    expected = RecordBox.get().add("avg", 12.88).getRecord();
    Assert.assertEquals(strategy.getResult().getRecords().get(0), expected);
    strategy.consume(RecordBox.get().addNull("someField").getRecord());
    expected = RecordBox.get().add("avg", 12.88).getRecord();
    Assert.assertEquals(strategy.getResult().getRecords().get(0), expected);
    strategy.consume(RecordBox.get().add("someField", 88.0).getRecord());
    expected = RecordBox.get().add("avg", 31.66).getRecord();
    Assert.assertEquals(strategy.getResult().getRecords().get(0), expected);
    Assert.assertEquals(strategy.getResult().getRecords().size(), 1);
    Assert.assertEquals(strategy.getRecords(), strategy.getResult().getRecords());
    Assert.assertEquals(strategy.getMetadata().asMap(), strategy.getResult().getMeta().asMap());
}
Also used : BulletRecord(com.yahoo.bullet.record.BulletRecord) GroupOperation(com.yahoo.bullet.querying.aggregations.grouping.GroupOperation) Test(org.testng.annotations.Test)

Aggregations

GroupOperation (com.yahoo.bullet.querying.aggregations.grouping.GroupOperation)24 Test (org.testng.annotations.Test)23 BulletRecord (com.yahoo.bullet.record.BulletRecord)18 Clip (com.yahoo.bullet.result.Clip)7 BulletConfig (com.yahoo.bullet.common.BulletConfig)6 GroupBy (com.yahoo.bullet.query.aggregations.GroupBy)6 RecordBox (com.yahoo.bullet.result.RecordBox)6 Collections.singletonMap (java.util.Collections.singletonMap)6 HashSet (java.util.HashSet)6 List (java.util.List)6 Map (java.util.Map)6 IntStream (java.util.stream.IntStream)6 Pair (org.apache.commons.lang3.tuple.Pair)6 Assert (org.testng.Assert)6 TestHelpers.addMetadata (com.yahoo.bullet.TestHelpers.addMetadata)5 TestHelpers.assertContains (com.yahoo.bullet.TestHelpers.assertContains)5 AggregationUtils.makeGroupFields (com.yahoo.bullet.querying.aggregations.AggregationUtils.makeGroupFields)5 COUNT (com.yahoo.bullet.querying.aggregations.grouping.GroupOperation.GroupOperationType.COUNT)5 SUM (com.yahoo.bullet.querying.aggregations.grouping.GroupOperation.GroupOperationType.SUM)5 KMVSketch (com.yahoo.bullet.querying.aggregations.sketches.KMVSketch)5