Search in sources :

Example 1 with GroupOperation

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

the class FilterBoltTest method testGroupAllCount.

@Test
public void testGroupAllCount() {
    // 15 Records will be consumed
    bolt = ComponentUtils.prepare(new DonableFilterBolt(15, new BulletStormConfig()), collector);
    Tuple query = makeIDTuple(TupleClassifier.Type.QUERY_TUPLE, "42", makeGroupFilterQuery("timestamp", asList("1", "2"), EQUALS, GROUP, 1, singletonList(new GroupOperation(COUNT, null, "cnt"))), METADATA);
    bolt.execute(query);
    BulletRecord record = RecordBox.get().add("timestamp", "1").getRecord();
    Tuple matching = makeRecordTuple(record);
    IntStream.range(0, 10).forEach(i -> bolt.execute(matching));
    BulletRecord another = RecordBox.get().getRecord();
    Tuple nonMatching = makeRecordTuple(another);
    IntStream.range(0, 5).forEach(i -> bolt.execute(nonMatching));
    bolt.execute(nonMatching);
    // Two to flush bolt
    Tuple tick = TupleUtils.makeTuple(TupleClassifier.Type.TICK_TUPLE);
    bolt.execute(tick);
    bolt.execute(tick);
    Assert.assertEquals(collector.getEmittedCount(), 1);
    GroupData actual = SerializerDeserializer.fromBytes(getRawPayloadOfNthTuple(1));
    BulletRecord expected = RecordBox.get().add("cnt", 10).getRecord();
    Assert.assertTrue(isEqual(actual, expected));
}
Also used : BulletRecord(com.yahoo.bullet.record.BulletRecord) TupleUtils.makeTuple(com.yahoo.bullet.storm.testing.TupleUtils.makeTuple) TupleUtils.makeRawTuple(com.yahoo.bullet.storm.testing.TupleUtils.makeRawTuple) Tuple(org.apache.storm.tuple.Tuple) TupleUtils.makeIDTuple(com.yahoo.bullet.storm.testing.TupleUtils.makeIDTuple) GroupOperation(com.yahoo.bullet.aggregations.grouping.GroupOperation) GroupData(com.yahoo.bullet.aggregations.grouping.GroupData) Test(org.testng.annotations.Test) DistributionTest(com.yahoo.bullet.aggregations.DistributionTest) TopKTest(com.yahoo.bullet.aggregations.TopKTest) CountDistinctTest(com.yahoo.bullet.aggregations.CountDistinctTest)

Example 2 with GroupOperation

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

the class JoinBoltTest method testQueryCountingMetrics.

@Test
public void testQueryCountingMetrics() {
    config.set(BulletStormConfig.TOPOLOGY_METRICS_BUILT_IN_ENABLE, true);
    config.validate();
    bolt = new DonableJoinBolt(config, 2, true);
    setup(bolt);
    String filterQuery = makeGroupFilterQuery("timestamp", asList("1", "2"), EQUALS, GROUP, 1, singletonList(new GroupOperation(COUNT, null, "cnt")));
    Tuple query = TupleUtils.makeIDTuple(TupleClassifier.Type.QUERY_TUPLE, "42", filterQuery, EMPTY);
    Assert.assertEquals(context.getLongMetric(TopologyConstants.CREATED_QUERIES_METRIC), Long.valueOf(0));
    Assert.assertEquals(context.getLongMetric(TopologyConstants.ACTIVE_QUERIES_METRIC), Long.valueOf(0));
    Assert.assertEquals(context.getLongMetric(TopologyConstants.IMPROPER_QUERIES_METRIC), Long.valueOf(0));
    bolt.execute(query);
    Assert.assertEquals(context.getLongMetric(TopologyConstants.CREATED_QUERIES_METRIC), Long.valueOf(1));
    Assert.assertEquals(context.getLongMetric(TopologyConstants.ACTIVE_QUERIES_METRIC), Long.valueOf(1));
    sendRawByteTuplesTo(bolt, "42", singletonList(getGroupDataWithCount("cnt", 21)));
    sendRawByteTuplesTo(bolt, "42", singletonList(getGroupDataWithCount("cnt", 21)));
    List<BulletRecord> result = singletonList(RecordBox.get().add("cnt", 42L).getRecord());
    Tuple expected = TupleUtils.makeTuple(TupleClassifier.Type.RESULT_TUPLE, "42", Clip.of(result).asJSON(), COMPLETED);
    Tuple tick = TupleUtils.makeTuple(TupleClassifier.Type.TICK_TUPLE);
    // Should cause an expiry and starts buffering the query for the query tickout
    bolt.execute(tick);
    // We need to tick the default query tickout to make the query emit
    for (int i = 0; i < BulletStormConfig.DEFAULT_JOIN_BOLT_QUERY_TICK_TIMEOUT - 1; ++i) {
        bolt.execute(tick);
    }
    Assert.assertFalse(wasResultEmittedTo(TopologyConstants.RESULT_STREAM, expected));
    Assert.assertEquals(context.getLongMetric(TopologyConstants.ACTIVE_QUERIES_METRIC), Long.valueOf(1));
    bolt.execute(tick);
    Assert.assertEquals(context.getLongMetric(TopologyConstants.ACTIVE_QUERIES_METRIC), Long.valueOf(0));
    Assert.assertTrue(wasResultEmittedTo(TopologyConstants.RESULT_STREAM, expected));
    Tuple metadata = TupleUtils.makeTuple(TupleClassifier.Type.FEEDBACK_TUPLE, "42", new Metadata(Metadata.Signal.COMPLETE, null));
    Assert.assertTrue(wasMetadataEmittedTo(TopologyConstants.FEEDBACK_STREAM, metadata));
    Assert.assertEquals(collector.getAllEmittedTo(TopologyConstants.RESULT_STREAM).count(), 1);
    Assert.assertEquals(collector.getAllEmittedTo(TopologyConstants.FEEDBACK_STREAM).count(), 1);
    bolt.execute(query);
    Assert.assertEquals(context.getLongMetric(TopologyConstants.CREATED_QUERIES_METRIC), Long.valueOf(2));
    Assert.assertEquals(context.getLongMetric(TopologyConstants.ACTIVE_QUERIES_METRIC), Long.valueOf(1));
    Assert.assertEquals(context.getLongMetric(TopologyConstants.IMPROPER_QUERIES_METRIC), Long.valueOf(0));
}
Also used : BulletRecord(com.yahoo.bullet.record.BulletRecord) Metadata(com.yahoo.bullet.pubsub.Metadata) GroupOperation(com.yahoo.bullet.aggregations.grouping.GroupOperation) Tuple(org.apache.storm.tuple.Tuple) 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)

Example 3 with GroupOperation

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

the class JoinBoltTest method testCustomMetricEmitInterval.

@Test
public void testCustomMetricEmitInterval() {
    Map<String, Number> mapping = new HashMap<>();
    mapping.put(TopologyConstants.ACTIVE_QUERIES_METRIC, 1);
    mapping.put(BulletStormConfig.DEFAULT_BUILT_IN_METRICS_INTERVAL_KEY, 10);
    config.set(BulletStormConfig.TOPOLOGY_METRICS_BUILT_IN_EMIT_INTERVAL_MAPPING, mapping);
    config.set(BulletStormConfig.TOPOLOGY_METRICS_BUILT_IN_ENABLE, true);
    bolt = new DonableJoinBolt(config, BulletStormConfig.DEFAULT_JOIN_BOLT_QUERY_TICK_TIMEOUT, false);
    setup(bolt);
    String filterQuery = makeGroupFilterQuery("timestamp", asList("1", "2"), EQUALS, GROUP, 1, singletonList(new GroupOperation(COUNT, null, "cnt")));
    Tuple query = TupleUtils.makeIDTuple(TupleClassifier.Type.QUERY_TUPLE, "42", filterQuery, EMPTY);
    Assert.assertEquals(context.getLongMetric(10, TopologyConstants.CREATED_QUERIES_METRIC), Long.valueOf(0));
    Assert.assertEquals(context.getLongMetric(1, TopologyConstants.ACTIVE_QUERIES_METRIC), Long.valueOf(0));
    Assert.assertEquals(context.getLongMetric(10, TopologyConstants.IMPROPER_QUERIES_METRIC), Long.valueOf(0));
    bolt.execute(query);
    Assert.assertEquals(context.getLongMetric(10, TopologyConstants.CREATED_QUERIES_METRIC), Long.valueOf(1));
    Assert.assertEquals(context.getLongMetric(1, TopologyConstants.ACTIVE_QUERIES_METRIC), Long.valueOf(1));
    Tuple tick = TupleUtils.makeTuple(TupleClassifier.Type.TICK_TUPLE);
    for (int i = 0; i <= BulletStormConfig.DEFAULT_JOIN_BOLT_QUERY_TICK_TIMEOUT; ++i) {
        bolt.execute(tick);
    }
    List<BulletRecord> result = singletonList(RecordBox.get().add("cnt", 0L).getRecord());
    Tuple expected = TupleUtils.makeTuple(TupleClassifier.Type.RESULT_TUPLE, "42", Clip.of(result).asJSON(), COMPLETED);
    Assert.assertTrue(wasResultEmittedTo(TopologyConstants.RESULT_STREAM, expected));
    Tuple metadata = TupleUtils.makeTuple(TupleClassifier.Type.FEEDBACK_TUPLE, "42", new Metadata(Metadata.Signal.COMPLETE, null));
    Assert.assertTrue(wasMetadataEmittedTo(TopologyConstants.FEEDBACK_STREAM, metadata));
    Assert.assertEquals(context.getLongMetric(10, TopologyConstants.CREATED_QUERIES_METRIC), Long.valueOf(1));
    Assert.assertEquals(context.getLongMetric(1, TopologyConstants.ACTIVE_QUERIES_METRIC), Long.valueOf(0));
    Assert.assertEquals(context.getLongMetric(10, TopologyConstants.IMPROPER_QUERIES_METRIC), Long.valueOf(0));
}
Also used : BulletRecord(com.yahoo.bullet.record.BulletRecord) HashMap(java.util.HashMap) Metadata(com.yahoo.bullet.pubsub.Metadata) GroupOperation(com.yahoo.bullet.aggregations.grouping.GroupOperation) Tuple(org.apache.storm.tuple.Tuple) 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)

Example 4 with GroupOperation

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

the class JoinBoltTest method testCounting.

@Test
public void testCounting() {
    bolt = new DonableJoinBolt(config, 5, true);
    setup(bolt);
    String filterQuery = makeGroupFilterQuery("timestamp", asList("1", "2"), EQUALS, GROUP, 1, singletonList(new GroupOperation(COUNT, null, "cnt")));
    Tuple query = TupleUtils.makeIDTuple(TupleClassifier.Type.QUERY_TUPLE, "42", filterQuery, EMPTY);
    bolt.execute(query);
    // Send 5 GroupData with counts 1, 2, 3, 4, 5 to the JoinBolt
    IntStream.range(1, 6).forEach(i -> sendRawByteTuplesTo(bolt, "42", singletonList(getGroupDataWithCount("cnt", i))));
    // 1 + 2 + 3 + 4 + 5
    List<BulletRecord> result = singletonList(RecordBox.get().add("cnt", 15L).getRecord());
    Tuple expected = TupleUtils.makeTuple(TupleClassifier.Type.RESULT_TUPLE, "42", Clip.of(result).asJSON(), COMPLETED);
    Tuple tick = TupleUtils.makeTuple(TupleClassifier.Type.TICK_TUPLE);
    // Should starts buffering the query for the query tickout
    bolt.execute(tick);
    for (int i = 0; i < BulletStormConfig.DEFAULT_JOIN_BOLT_QUERY_TICK_TIMEOUT - 1; ++i) {
        bolt.execute(tick);
        Assert.assertFalse(wasResultEmittedTo(TopologyConstants.RESULT_STREAM, expected));
    }
    bolt.execute(tick);
    Assert.assertTrue(wasResultEmittedTo(TopologyConstants.RESULT_STREAM, expected));
    Tuple metadata = TupleUtils.makeTuple(TupleClassifier.Type.FEEDBACK_TUPLE, "42", new Metadata(Metadata.Signal.COMPLETE, null));
    Assert.assertTrue(wasMetadataEmittedTo(TopologyConstants.FEEDBACK_STREAM, metadata));
    Assert.assertEquals(collector.getAllEmittedTo(TopologyConstants.RESULT_STREAM).count(), 1);
    Assert.assertEquals(collector.getAllEmittedTo(TopologyConstants.FEEDBACK_STREAM).count(), 1);
}
Also used : BulletRecord(com.yahoo.bullet.record.BulletRecord) Metadata(com.yahoo.bullet.pubsub.Metadata) GroupOperation(com.yahoo.bullet.aggregations.grouping.GroupOperation) Tuple(org.apache.storm.tuple.Tuple) 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)

Example 5 with GroupOperation

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

the class GroupAllTest 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"));
    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 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();
    groupAll.combine(serialized);
    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());
}
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)

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