Search in sources :

Example 6 with GroupOperation

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

the class GroupAllTest 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"));
    GroupAll groupAll = makeGroupAll(operations);
    groupAll.consume(RecordBox.get().add("minField", -8.8).add("groupField", 3.14).getRecord());
    groupAll.consume(RecordBox.get().add("minField", 0.0).addNull("groupField").getRecord());
    groupAll.consume(RecordBox.get().add("minField", 51.44).add("groupField", -4.88).getRecord());
    groupAll.consume(RecordBox.get().add("minField", -8.8).add("groupField", 12345.67).getRecord());
    groupAll.consume(RecordBox.get().addNull("minField").add("groupField", 2.718).getRecord());
    groupAll.consume(RecordBox.get().add("minField", -51.0).addNull("groupField").getRecord());
    groupAll.consume(RecordBox.get().add("minField", 0).add("groupField", 1).getRecord());
    groupAll.consume(RecordBox.get().add("minField", 44.8).add("groupField", -51.44).getRecord());
    Assert.assertNotNull(groupAll.getData());
    List<BulletRecord> aggregate = groupAll.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(groupAll.getRecords(), aggregate);
    Assert.assertEquals(groupAll.getMetadata().asMap(), groupAll.getResult().getMeta().asMap());
    groupAll.reset();
    groupAll.consume(RecordBox.get().add("minField", -8.8).add("groupField", 3.14).getRecord());
    groupAll.consume(RecordBox.get().add("minField", 0.0).addNull("groupField").getRecord());
    Assert.assertNotNull(groupAll.getData());
    aggregate = groupAll.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(groupAll.getRecords(), aggregate);
    Assert.assertEquals(groupAll.getMetadata().asMap(), groupAll.getResult().getMeta().asMap());
}
Also used : BulletRecord(com.yahoo.bullet.record.BulletRecord) AggregationUtils.makeGroupOperation(com.yahoo.bullet.parsing.AggregationUtils.makeGroupOperation) GroupOperation(com.yahoo.bullet.aggregations.grouping.GroupOperation) Test(org.testng.annotations.Test)

Example 7 with GroupOperation

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

the class JoinBoltTest method getGroupDataWithCount.

private static byte[] getGroupDataWithCount(String countField, int count) {
    GroupData groupData = new GroupData(new HashSet<>(singletonList(new GroupOperation(COUNT, null, countField))));
    IntStream.range(0, count).forEach(i -> groupData.consume(RecordBox.get().getRecord()));
    return SerializerDeserializer.toBytes(groupData);
}
Also used : GroupOperation(com.yahoo.bullet.aggregations.grouping.GroupOperation) GroupData(com.yahoo.bullet.aggregations.grouping.GroupData)

Example 8 with GroupOperation

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

the class JoinBoltTest method testGroupBy.

@Test
public void testGroupBy() {
    final int entries = 16;
    BulletConfig bulletConfig = GroupByTest.makeConfiguration(entries);
    GroupBy groupBy = GroupByTest.makeGroupBy(bulletConfig, singletonMap("fieldA", "A"), entries, AggregationUtils.makeGroupOperation(COUNT, null, "cnt"), AggregationUtils.makeGroupOperation(SUM, "fieldB", "sumB"));
    IntStream.range(0, 256).mapToObj(i -> RecordBox.get().add("fieldA", i % 16).add("fieldB", i / 16).getRecord()).forEach(groupBy::consume);
    byte[] first = groupBy.getData();
    groupBy = GroupByTest.makeGroupBy(bulletConfig, singletonMap("fieldA", "A"), entries, AggregationUtils.makeGroupOperation(COUNT, null, "cnt"), AggregationUtils.makeGroupOperation(SUM, "fieldB", "sumB"));
    IntStream.range(256, 1024).mapToObj(i -> RecordBox.get().add("fieldA", i % 16).add("fieldB", i / 16).getRecord()).forEach(groupBy::consume);
    byte[] second = groupBy.getData();
    // Send generated data to JoinBolt
    bolt = new DonableJoinBolt(config, 2, true);
    setup(bolt);
    List<GroupOperation> operations = asList(new GroupOperation(COUNT, null, "cnt"), new GroupOperation(SUM, "fieldB", "sumB"));
    String queryString = makeGroupFilterQuery("ts", singletonList("1"), EQUALS, GROUP, entries, operations, Pair.of("fieldA", "A"));
    Tuple query = TupleUtils.makeIDTuple(TupleClassifier.Type.QUERY_TUPLE, "42", queryString, EMPTY);
    bolt.execute(query);
    sendRawByteTuplesTo(bolt, "42", asList(first, second));
    Tuple tick = TupleUtils.makeTuple(TupleClassifier.Type.TICK_TUPLE);
    bolt.execute(tick);
    for (int i = 0; i < BulletStormConfig.DEFAULT_JOIN_BOLT_QUERY_TICK_TIMEOUT - 1; ++i) {
        bolt.execute(tick);
        Assert.assertEquals(collector.getEmittedCount(), 0);
    }
    bolt.execute(tick);
    Assert.assertEquals(collector.getEmittedCount(), 2);
    String response = (String) collector.getMthElementFromNthTupleEmittedTo(TopologyConstants.RESULT_STREAM, 1, 1).get();
    JsonParser parser = new JsonParser();
    JsonObject actual = parser.parse(response).getAsJsonObject();
    JsonArray actualRecords = actual.get(Clip.RECORDS_KEY).getAsJsonArray();
    Assert.assertEquals(actualRecords.size(), 16);
}
Also used : JsonObject(com.google.gson.JsonObject) GROUP(com.yahoo.bullet.parsing.Aggregation.Type.GROUP) COUNT(com.yahoo.bullet.aggregations.grouping.GroupOperation.GroupOperationType.COUNT) TopK(com.yahoo.bullet.aggregations.TopK) BulletError(com.yahoo.bullet.common.BulletError) Concept(com.yahoo.bullet.result.Meta.Concept) ParsingError(com.yahoo.bullet.parsing.ParsingError) Test(org.testng.annotations.Test) RecordBox(com.yahoo.bullet.result.RecordBox) ErrorType(com.yahoo.sketches.frequencies.ErrorType) EQUALS(com.yahoo.bullet.parsing.Clause.Operation.EQUALS) PROBABILITY_FIELD(com.yahoo.bullet.aggregations.sketches.QuantileSketch.PROBABILITY_FIELD) Collections.singletonList(java.util.Collections.singletonList) CustomCollector(com.yahoo.bullet.storm.testing.CustomCollector) Pair(org.apache.commons.lang3.tuple.Pair) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Metadata(com.yahoo.bullet.pubsub.Metadata) Mockito.doReturn(org.mockito.Mockito.doReturn) GroupData(com.yahoo.bullet.aggregations.grouping.GroupData) QueryUtils.makeAggregationQuery(com.yahoo.bullet.parsing.QueryUtils.makeAggregationQuery) GroupBy(com.yahoo.bullet.aggregations.GroupBy) ComponentUtils(com.yahoo.bullet.storm.testing.ComponentUtils) BulletRecord(com.yahoo.bullet.record.BulletRecord) AggregationUtils(com.yahoo.bullet.parsing.AggregationUtils) BeforeMethod(org.testng.annotations.BeforeMethod) GroupByTest(com.yahoo.bullet.aggregations.GroupByTest) Fields(org.apache.storm.tuple.Fields) CustomTopologyContext(com.yahoo.bullet.storm.testing.CustomTopologyContext) SlidingRecord(com.yahoo.bullet.windowing.SlidingRecord) DistributionTest(com.yahoo.bullet.aggregations.DistributionTest) Serializable(java.io.Serializable) RateLimitError(com.yahoo.bullet.querying.RateLimitError) GroupOperation(com.yahoo.bullet.aggregations.grouping.GroupOperation) Querier(com.yahoo.bullet.querying.Querier) JsonArray(com.google.gson.JsonArray) List(java.util.List) Distribution(com.yahoo.bullet.aggregations.Distribution) NEGATIVE_INFINITY_START(com.yahoo.bullet.aggregations.sketches.QuantileSketch.NEGATIVE_INFINITY_START) BulletConfig(com.yahoo.bullet.common.BulletConfig) AdditionalAnswers.returnsElementsOf(org.mockito.AdditionalAnswers.returnsElementsOf) Window(com.yahoo.bullet.parsing.Window) IRichBolt(org.apache.storm.topology.IRichBolt) END_EXCLUSIVE(com.yahoo.bullet.aggregations.sketches.QuantileSketch.END_EXCLUSIVE) TupleUtils(com.yahoo.bullet.storm.testing.TupleUtils) IntStream(java.util.stream.IntStream) TopKTest(com.yahoo.bullet.aggregations.TopKTest) Setter(lombok.Setter) TestHelpers.assertJSONEquals(com.yahoo.bullet.storm.testing.TestHelpers.assertJSONEquals) SerializerDeserializer(com.yahoo.bullet.common.SerializerDeserializer) HashMap(java.util.HashMap) JsonParser(com.google.gson.JsonParser) Mockito.spy(org.mockito.Mockito.spy) TestHelpers.getListBytes(com.yahoo.bullet.storm.testing.TestHelpers.getListBytes) Clip(com.yahoo.bullet.result.Clip) SUM(com.yahoo.bullet.aggregations.grouping.GroupOperation.GroupOperationType.SUM) SEPARATOR(com.yahoo.bullet.aggregations.sketches.QuantileSketch.SEPARATOR) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Tuple(org.apache.storm.tuple.Tuple) Assert(org.testng.Assert) CountDistinct(com.yahoo.bullet.aggregations.CountDistinct) AggregationUtils.makeAttributes(com.yahoo.bullet.parsing.AggregationUtils.makeAttributes) Collections.singletonMap(java.util.Collections.singletonMap) TOP_K(com.yahoo.bullet.parsing.Aggregation.Type.TOP_K) Aggregation(com.yahoo.bullet.parsing.Aggregation) Meta(com.yahoo.bullet.result.Meta) COUNT_FIELD(com.yahoo.bullet.aggregations.sketches.QuantileSketch.COUNT_FIELD) POSITIVE_INFINITY_END(com.yahoo.bullet.aggregations.sketches.QuantileSketch.POSITIVE_INFINITY_END) COUNT_DISTINCT(com.yahoo.bullet.parsing.Aggregation.Type.COUNT_DISTINCT) CustomOutputFieldsDeclarer(com.yahoo.bullet.storm.testing.CustomOutputFieldsDeclarer) START_INCLUSIVE(com.yahoo.bullet.aggregations.sketches.QuantileSketch.START_INCLUSIVE) CountDistinctTest(com.yahoo.bullet.aggregations.CountDistinctTest) RAW(com.yahoo.bullet.parsing.Aggregation.Type.RAW) DISTRIBUTION(com.yahoo.bullet.parsing.Aggregation.Type.DISTRIBUTION) QueryUtils.makeGroupFilterQuery(com.yahoo.bullet.parsing.QueryUtils.makeGroupFilterQuery) RANGE_FIELD(com.yahoo.bullet.aggregations.sketches.QuantileSketch.RANGE_FIELD) GroupBy(com.yahoo.bullet.aggregations.GroupBy) JsonObject(com.google.gson.JsonObject) JsonArray(com.google.gson.JsonArray) BulletConfig(com.yahoo.bullet.common.BulletConfig) GroupOperation(com.yahoo.bullet.aggregations.grouping.GroupOperation) Tuple(org.apache.storm.tuple.Tuple) JsonParser(com.google.gson.JsonParser) Test(org.testng.annotations.Test) GroupByTest(com.yahoo.bullet.aggregations.GroupByTest) DistributionTest(com.yahoo.bullet.aggregations.DistributionTest) TopKTest(com.yahoo.bullet.aggregations.TopKTest) CountDistinctTest(com.yahoo.bullet.aggregations.CountDistinctTest)

Aggregations

GroupOperation (com.yahoo.bullet.aggregations.grouping.GroupOperation)8 BulletRecord (com.yahoo.bullet.record.BulletRecord)7 Test (org.testng.annotations.Test)7 CountDistinctTest (com.yahoo.bullet.aggregations.CountDistinctTest)5 DistributionTest (com.yahoo.bullet.aggregations.DistributionTest)5 TopKTest (com.yahoo.bullet.aggregations.TopKTest)5 GroupByTest (com.yahoo.bullet.aggregations.GroupByTest)4 Tuple (org.apache.storm.tuple.Tuple)4 GroupData (com.yahoo.bullet.aggregations.grouping.GroupData)3 Metadata (com.yahoo.bullet.pubsub.Metadata)3 AggregationUtils.makeGroupOperation (com.yahoo.bullet.parsing.AggregationUtils.makeGroupOperation)2 JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1 JsonParser (com.google.gson.JsonParser)1 CountDistinct (com.yahoo.bullet.aggregations.CountDistinct)1 Distribution (com.yahoo.bullet.aggregations.Distribution)1 GroupBy (com.yahoo.bullet.aggregations.GroupBy)1 TopK (com.yahoo.bullet.aggregations.TopK)1 COUNT (com.yahoo.bullet.aggregations.grouping.GroupOperation.GroupOperationType.COUNT)1 SUM (com.yahoo.bullet.aggregations.grouping.GroupOperation.GroupOperationType.SUM)1