Search in sources :

Example 6 with GroupOperation

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

the class GroupAllStrategyTest method testResetting.

@Test
public void testResetting() {
    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());
    strategy.consume(RecordBox.get().add("minField", -8.8).add("groupField", 12345.67).getRecord());
    strategy.consume(RecordBox.get().addNull("minField").add("groupField", 2.718).getRecord());
    strategy.consume(RecordBox.get().add("minField", -51.0).addNull("groupField").getRecord());
    strategy.consume(RecordBox.get().add("minField", 0).add("groupField", 1).getRecord());
    strategy.consume(RecordBox.get().add("minField", 44.8).add("groupField", -51.44).getRecord());
    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());
    strategy.reset();
    strategy.consume(RecordBox.get().add("minField", -8.8).add("groupField", 3.14).getRecord());
    strategy.consume(RecordBox.get().add("minField", 0.0).addNull("groupField").getRecord());
    Assert.assertNotNull(strategy.getData());
    aggregate = strategy.getResult().getRecords();
    Assert.assertEquals(aggregate.size(), 1);
    actual = aggregate.get(0);
    expected = RecordBox.get().add("myCount", 2L).add("myMin", -8.8).add("groupAvg", 3.14).add("groupMin", 3.14).add("groupSum", 3.14).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 7 with GroupOperation

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

the class GroupByTest method testToString.

@Test
public void testToString() {
    GroupOperation operation = new GroupOperation(GroupOperation.GroupOperationType.SUM, "abc", "sum");
    GroupBy aggregation = new GroupBy(null, Collections.singletonMap("abc", "def"), Collections.singleton(operation));
    Assert.assertEquals(aggregation.toString(), "{size: null, type: GROUP, fields: {abc=def}, operations: [{type: SUM, field: abc, name: sum}]}");
}
Also used : GroupOperation(com.yahoo.bullet.querying.aggregations.grouping.GroupOperation) Test(org.testng.annotations.Test)

Example 8 with GroupOperation

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

the class TupleSketchingStrategyTest method testResetting.

@Test
public void testResetting() {
    List<String> fields = asList("fieldA", "fieldB");
    TupleSketchingStrategy groupBy = makeGroupBy(fields, 5, new GroupOperation(COUNT, null, "count"), new GroupOperation(SUM, "price", "priceSum"));
    BulletRecord recordA = RecordBox.get().add("fieldA", "foo").add("fieldB", "bar").add("price", 3).getRecord();
    BulletRecord recordB = RecordBox.get().add("fieldA", "null").add("fieldB", "bar").add("price", 1).getRecord();
    IntStream.range(0, 30).mapToObj(i -> recordA).forEach(groupBy::consume);
    IntStream.range(0, 10).mapToObj(i -> recordB).forEach(groupBy::consume);
    BulletRecord expectedA = RecordBox.get().add("fieldA", "foo").add("fieldB", "bar").add("count", 30L).add("priceSum", 90.0).getRecord();
    BulletRecord expectedB = RecordBox.get().add("fieldA", "null").add("fieldB", "bar").add("count", 10L).add("priceSum", 10.0).getRecord();
    Clip aggregate = groupBy.getResult();
    Assert.assertNotNull(aggregate);
    List<BulletRecord> records = aggregate.getRecords();
    Assert.assertEquals(records.size(), 2);
    assertContains(records, expectedA);
    assertContains(records, expectedB);
    Assert.assertEquals(groupBy.getRecords(), aggregate.getRecords());
    Assert.assertEquals(groupBy.getMetadata().asMap(), aggregate.getMeta().asMap());
    groupBy.reset();
    BulletRecord recordC = RecordBox.get().add("fieldA", "foo").add("fieldB", "bar").add("price", 3).getRecord();
    BulletRecord recordD = RecordBox.get().addNull("fieldA").addNull("fieldB").add("price", 10).getRecord();
    IntStream.range(0, 10).mapToObj(i -> recordB).forEach(groupBy::consume);
    IntStream.range(0, 30).mapToObj(i -> recordC).forEach(groupBy::consume);
    IntStream.range(0, 10).mapToObj(i -> recordD).forEach(groupBy::consume);
    aggregate = groupBy.getResult();
    Assert.assertNotNull(aggregate);
    records = aggregate.getRecords();
    Assert.assertEquals(records.size(), 3);
    expectedA = RecordBox.get().add("fieldA", "null").add("fieldB", "bar").add("count", 10L).add("priceSum", 10.0).getRecord();
    expectedB = RecordBox.get().add("fieldA", "foo").add("fieldB", "bar").add("count", 30L).add("priceSum", 90.0).getRecord();
    BulletRecord expectedC = RecordBox.get().add("fieldA", "null").add("fieldB", "null").add("count", 10L).add("priceSum", 100.0).getRecord();
    assertContains(records, expectedA);
    assertContains(records, expectedB);
    assertContains(records, expectedC);
    Assert.assertEquals(groupBy.getRecords(), aggregate.getRecords());
    Assert.assertEquals(groupBy.getMetadata().asMap(), aggregate.getMeta().asMap());
}
Also used : IntStream(java.util.stream.IntStream) COUNT(com.yahoo.bullet.querying.aggregations.grouping.GroupOperation.GroupOperationType.COUNT) AggregationUtils.makeGroupFields(com.yahoo.bullet.querying.aggregations.AggregationUtils.makeGroupFields) BulletRecord(com.yahoo.bullet.record.BulletRecord) SUM(com.yahoo.bullet.querying.aggregations.grouping.GroupOperation.GroupOperationType.SUM) Concept(com.yahoo.bullet.result.Meta.Concept) Set(java.util.Set) Test(org.testng.annotations.Test) RecordBox(com.yahoo.bullet.result.RecordBox) GroupOperation(com.yahoo.bullet.querying.aggregations.grouping.GroupOperation) Clip(com.yahoo.bullet.result.Clip) Collections.singletonList(java.util.Collections.singletonList) KMVSketch(com.yahoo.bullet.querying.aggregations.sketches.KMVSketch) HashSet(java.util.HashSet) GroupBy(com.yahoo.bullet.query.aggregations.GroupBy) List(java.util.List) Pair(org.apache.commons.lang3.tuple.Pair) Assert(org.testng.Assert) TestHelpers.addMetadata(com.yahoo.bullet.TestHelpers.addMetadata) Arrays.asList(java.util.Arrays.asList) BulletConfig(com.yahoo.bullet.common.BulletConfig) Map(java.util.Map) Collections.singletonMap(java.util.Collections.singletonMap) TestHelpers.assertContains(com.yahoo.bullet.TestHelpers.assertContains) Clip(com.yahoo.bullet.result.Clip) BulletRecord(com.yahoo.bullet.record.BulletRecord) GroupOperation(com.yahoo.bullet.querying.aggregations.grouping.GroupOperation) Test(org.testng.annotations.Test)

Example 9 with GroupOperation

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

the class TupleSketchingStrategyTest method testMoreGroupsThanNominalEntries.

@Test
public void testMoreGroupsThanNominalEntries() {
    Map<String, String> fields = singletonMap("fieldA", "A");
    // Nominal Entries is 32. Aggregation size is also 32
    TupleSketchingStrategy groupBy = makeGroupBy(makeConfiguration(32), fields, 32, singletonList(new GroupOperation(COUNT, null, "count")), ALL_METADATA);
    // Generate 4 batches of 64 records with 0 - 63 in fieldA.
    IntStream.range(0, 256).mapToObj(i -> RecordBox.get().add("fieldA", i % 64).getRecord()).forEach(groupBy::consume);
    Clip aggregate = groupBy.getResult();
    Assert.assertNotNull(aggregate);
    Map<String, Object> meta = aggregate.getMeta().asMap();
    Assert.assertEquals(meta.size(), 1);
    List<BulletRecord> records = aggregate.getRecords();
    Assert.assertEquals(records.size(), 32);
    Set<String> groups = new HashSet<>();
    for (BulletRecord record : records) {
        groups.add((String) record.typedGet("A").getValue());
        Assert.assertEquals(record.typedGet("count").getValue(), 4L);
    }
    Assert.assertEquals(groups.size(), 32);
    Assert.assertEquals(groupBy.getRecords(), aggregate.getRecords());
    Assert.assertEquals(groupBy.getMetadata().asMap(), aggregate.getMeta().asMap());
}
Also used : IntStream(java.util.stream.IntStream) COUNT(com.yahoo.bullet.querying.aggregations.grouping.GroupOperation.GroupOperationType.COUNT) AggregationUtils.makeGroupFields(com.yahoo.bullet.querying.aggregations.AggregationUtils.makeGroupFields) BulletRecord(com.yahoo.bullet.record.BulletRecord) SUM(com.yahoo.bullet.querying.aggregations.grouping.GroupOperation.GroupOperationType.SUM) Concept(com.yahoo.bullet.result.Meta.Concept) Set(java.util.Set) Test(org.testng.annotations.Test) RecordBox(com.yahoo.bullet.result.RecordBox) GroupOperation(com.yahoo.bullet.querying.aggregations.grouping.GroupOperation) Clip(com.yahoo.bullet.result.Clip) Collections.singletonList(java.util.Collections.singletonList) KMVSketch(com.yahoo.bullet.querying.aggregations.sketches.KMVSketch) HashSet(java.util.HashSet) GroupBy(com.yahoo.bullet.query.aggregations.GroupBy) List(java.util.List) Pair(org.apache.commons.lang3.tuple.Pair) Assert(org.testng.Assert) TestHelpers.addMetadata(com.yahoo.bullet.TestHelpers.addMetadata) Arrays.asList(java.util.Arrays.asList) BulletConfig(com.yahoo.bullet.common.BulletConfig) Map(java.util.Map) Collections.singletonMap(java.util.Collections.singletonMap) TestHelpers.assertContains(com.yahoo.bullet.TestHelpers.assertContains) Clip(com.yahoo.bullet.result.Clip) BulletRecord(com.yahoo.bullet.record.BulletRecord) GroupOperation(com.yahoo.bullet.querying.aggregations.grouping.GroupOperation) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 10 with GroupOperation

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

the class TupleSketchingStrategyTest method testCombiningAndConsuming.

@Test
public void testCombiningAndConsuming() {
    List<String> fields = asList("fieldA", "fieldB");
    TupleSketchingStrategy groupBy = makeGroupBy(fields, 5, new GroupOperation(COUNT, null, "count"), new GroupOperation(SUM, "price", "priceSum"));
    BulletRecord recordA = RecordBox.get().add("fieldA", "foo").add("fieldB", "bar").add("price", 3).getRecord();
    BulletRecord recordB = RecordBox.get().add("fieldA", "null").add("fieldB", "bar").add("price", 1).getRecord();
    IntStream.range(0, 30).mapToObj(i -> recordA).forEach(groupBy::consume);
    IntStream.range(0, 10).mapToObj(i -> recordB).forEach(groupBy::consume);
    byte[] serialized = groupBy.getData();
    // Remake it
    groupBy = makeGroupBy(fields, 5, new GroupOperation(COUNT, null, "count"), new GroupOperation(SUM, "price", "priceSum"));
    BulletRecord recordC = RecordBox.get().add("fieldA", "foo").add("fieldB", "bar").add("price", 3).getRecord();
    BulletRecord recordD = RecordBox.get().addNull("fieldA").addNull("fieldB").add("price", 10).getRecord();
    IntStream.range(0, 30).mapToObj(i -> recordC).forEach(groupBy::consume);
    IntStream.range(0, 10).mapToObj(i -> recordD).forEach(groupBy::consume);
    groupBy.combine(serialized);
    Clip aggregate = groupBy.getResult();
    Assert.assertNotNull(aggregate);
    List<BulletRecord> records = aggregate.getRecords();
    Assert.assertEquals(records.size(), 3);
    BulletRecord expectedA = RecordBox.get().add("fieldA", "foo").add("fieldB", "bar").add("count", 60L).add("priceSum", 180.0).getRecord();
    BulletRecord expectedB = RecordBox.get().add("fieldA", "null").add("fieldB", "bar").add("count", 10L).add("priceSum", 10.0).getRecord();
    BulletRecord expectedC = RecordBox.get().add("fieldA", "null").add("fieldB", "null").add("count", 10L).add("priceSum", 100.0).getRecord();
    assertContains(records, expectedA);
    assertContains(records, expectedB);
    assertContains(records, expectedC);
    Assert.assertEquals(groupBy.getRecords(), aggregate.getRecords());
    Assert.assertEquals(groupBy.getMetadata().asMap(), aggregate.getMeta().asMap());
}
Also used : IntStream(java.util.stream.IntStream) COUNT(com.yahoo.bullet.querying.aggregations.grouping.GroupOperation.GroupOperationType.COUNT) AggregationUtils.makeGroupFields(com.yahoo.bullet.querying.aggregations.AggregationUtils.makeGroupFields) BulletRecord(com.yahoo.bullet.record.BulletRecord) SUM(com.yahoo.bullet.querying.aggregations.grouping.GroupOperation.GroupOperationType.SUM) Concept(com.yahoo.bullet.result.Meta.Concept) Set(java.util.Set) Test(org.testng.annotations.Test) RecordBox(com.yahoo.bullet.result.RecordBox) GroupOperation(com.yahoo.bullet.querying.aggregations.grouping.GroupOperation) Clip(com.yahoo.bullet.result.Clip) Collections.singletonList(java.util.Collections.singletonList) KMVSketch(com.yahoo.bullet.querying.aggregations.sketches.KMVSketch) HashSet(java.util.HashSet) GroupBy(com.yahoo.bullet.query.aggregations.GroupBy) List(java.util.List) Pair(org.apache.commons.lang3.tuple.Pair) Assert(org.testng.Assert) TestHelpers.addMetadata(com.yahoo.bullet.TestHelpers.addMetadata) Arrays.asList(java.util.Arrays.asList) BulletConfig(com.yahoo.bullet.common.BulletConfig) Map(java.util.Map) Collections.singletonMap(java.util.Collections.singletonMap) TestHelpers.assertContains(com.yahoo.bullet.TestHelpers.assertContains) Clip(com.yahoo.bullet.result.Clip) 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