Search in sources :

Example 56 with BulletConfig

use of com.yahoo.bullet.common.BulletConfig in project bullet-storm by yahoo.

the class JoinBoltTest method testDistribution.

@Test
public void testDistribution() {
    BulletConfig bulletConfig = DistributionTest.makeConfiguration(10, 128);
    Distribution distribution = DistributionTest.makeDistribution(bulletConfig, makeAttributes(Distribution.Type.PMF, 3), "field", 10, null);
    IntStream.range(0, 50).mapToObj(i -> RecordBox.get().add("field", i).getRecord()).forEach(distribution::consume);
    byte[] first = distribution.getData();
    distribution = DistributionTest.makeDistribution(bulletConfig, makeAttributes(Distribution.Type.PMF, 3), "field", 10, null);
    IntStream.range(50, 101).mapToObj(i -> RecordBox.get().add("field", i).getRecord()).forEach(distribution::consume);
    byte[] second = distribution.getData();
    bolt = new DonableJoinBolt(config, 2, true);
    setup(bolt);
    Tuple query = TupleUtils.makeIDTuple(TupleClassifier.Type.QUERY_TUPLE, "42", makeAggregationQuery(DISTRIBUTION, 10, Distribution.Type.PMF, "field", null, null, null, null, 3), EMPTY);
    bolt.execute(query);
    sendRawByteTuplesTo(bolt, "42", asList(first, second));
    BulletRecord expectedA = RecordBox.get().add(RANGE_FIELD, NEGATIVE_INFINITY_START + SEPARATOR + 0.0 + END_EXCLUSIVE).add(COUNT_FIELD, 0.0).add(PROBABILITY_FIELD, 0.0).getRecord();
    BulletRecord expectedB = RecordBox.get().add(RANGE_FIELD, START_INCLUSIVE + 0.0 + SEPARATOR + 50.0 + END_EXCLUSIVE).add(COUNT_FIELD, 50.0).add(PROBABILITY_FIELD, 50.0 / 101).getRecord();
    BulletRecord expectedC = RecordBox.get().add(RANGE_FIELD, START_INCLUSIVE + 50.0 + SEPARATOR + 100.0 + END_EXCLUSIVE).add(COUNT_FIELD, 50.0).add(PROBABILITY_FIELD, 50.0 / 101).getRecord();
    BulletRecord expectedD = RecordBox.get().add(RANGE_FIELD, START_INCLUSIVE + 100.0 + SEPARATOR + POSITIVE_INFINITY_END).add(COUNT_FIELD, 1.0).add(PROBABILITY_FIELD, 1.0 / 101).getRecord();
    List<BulletRecord> results = asList(expectedA, expectedB, expectedC, expectedD);
    Tuple expected = TupleUtils.makeTuple(TupleClassifier.Type.RESULT_TUPLE, "42", Clip.of(results).asJSON(), COMPLETED);
    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.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 : 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) BulletRecord(com.yahoo.bullet.record.BulletRecord) Distribution(com.yahoo.bullet.aggregations.Distribution) Metadata(com.yahoo.bullet.pubsub.Metadata) BulletConfig(com.yahoo.bullet.common.BulletConfig) 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 57 with BulletConfig

use of com.yahoo.bullet.common.BulletConfig in project bullet-core by yahoo.

the class GroupByTest method testAttributeOperationsUnknownOperation.

@Test
public void testAttributeOperationsUnknownOperation() {
    Aggregation aggregation = makeAggregation(emptyMap(), 10, null);
    aggregation.setAttributes(makeAttributes(makeGroupOperation(COUNT, null, "bar"), makeGroupOperation(COUNT_FIELD, "foo", "foo_avg")));
    GroupBy groupBy = makeGroupBy(new BulletConfig(), aggregation, ALL_METADATA);
    // The bad operation should have been thrown out.
    Assert.assertFalse(groupBy.initialize().isPresent());
}
Also used : Aggregation(com.yahoo.bullet.parsing.Aggregation) BulletConfig(com.yahoo.bullet.common.BulletConfig) Test(org.testng.annotations.Test)

Example 58 with BulletConfig

use of com.yahoo.bullet.common.BulletConfig in project bullet-core by yahoo.

the class GroupByTest method testAttributeOperationsDuplicateOperation.

@Test
public void testAttributeOperationsDuplicateOperation() {
    Aggregation aggregation = makeAggregation(emptyMap(), 10, null);
    aggregation.setAttributes(makeAttributes(makeGroupOperation(COUNT, null, null), makeGroupOperation(SUM, "foo", null), makeGroupOperation(COUNT, null, null), makeGroupOperation(SUM, "bar", null), makeGroupOperation(SUM, "foo", null), makeGroupOperation(SUM, "bar", null)));
    GroupBy groupBy = makeGroupBy(new BulletConfig(), aggregation, ALL_METADATA);
    // The bad ones should be removed.
    Assert.assertFalse(groupBy.initialize().isPresent());
}
Also used : Aggregation(com.yahoo.bullet.parsing.Aggregation) BulletConfig(com.yahoo.bullet.common.BulletConfig) Test(org.testng.annotations.Test)

Example 59 with BulletConfig

use of com.yahoo.bullet.common.BulletConfig in project bullet-core by yahoo.

the class RawTest method makeRaw.

private static Raw makeRaw(int size, int maxSize) {
    Aggregation aggregation = new Aggregation();
    aggregation.setSize(size);
    BulletConfig config = new BulletConfig();
    config.set(BulletConfig.RAW_AGGREGATION_MAX_SIZE, maxSize);
    Raw raw = new Raw(aggregation, config.validate());
    raw.initialize();
    return raw;
}
Also used : Aggregation(com.yahoo.bullet.parsing.Aggregation) BulletConfig(com.yahoo.bullet.common.BulletConfig)

Example 60 with BulletConfig

use of com.yahoo.bullet.common.BulletConfig in project bullet-core by yahoo.

the class QuerierTest method testRawQueriesWithoutWindowsThatAreClosedAreNotTimeBased.

@Test
public void testRawQueriesWithoutWindowsThatAreClosedAreNotTimeBased() {
    BulletConfig config = new BulletConfig();
    config.set(BulletConfig.RAW_AGGREGATION_MAX_SIZE, 10);
    config.validate();
    Query query = new Query();
    Aggregation aggregation = new Aggregation();
    aggregation.setType(Aggregation.Type.RAW);
    query.setAggregation(aggregation);
    query.configure(config);
    Querier querier = make(Querier.Mode.ALL, query, config);
    Assert.assertFalse(querier.isClosed());
    Assert.assertFalse(querier.shouldBuffer());
    Assert.assertEquals(querier.getWindow().getClass(), Basic.class);
    querier.consume(RecordBox.get().getRecord());
    Assert.assertFalse(querier.isClosed());
    Assert.assertFalse(querier.shouldBuffer());
    IntStream.range(0, 9).forEach(i -> querier.consume(RecordBox.get().getRecord()));
    Assert.assertTrue(querier.isClosed());
    Assert.assertFalse(querier.shouldBuffer());
}
Also used : Aggregation(com.yahoo.bullet.parsing.Aggregation) QueryUtils.makeAggregationQuery(com.yahoo.bullet.parsing.QueryUtils.makeAggregationQuery) QueryUtils.makeProjectionFilterQuery(com.yahoo.bullet.parsing.QueryUtils.makeProjectionFilterQuery) QueryUtils.makeRawFullQuery(com.yahoo.bullet.parsing.QueryUtils.makeRawFullQuery) Query(com.yahoo.bullet.parsing.Query) BulletConfig(com.yahoo.bullet.common.BulletConfig) Test(org.testng.annotations.Test)

Aggregations

BulletConfig (com.yahoo.bullet.common.BulletConfig)101 Test (org.testng.annotations.Test)87 Aggregation (com.yahoo.bullet.parsing.Aggregation)37 List (java.util.List)25 Query (com.yahoo.bullet.parsing.Query)20 QueryUtils.makeAggregationQuery (com.yahoo.bullet.parsing.QueryUtils.makeAggregationQuery)17 BulletError (com.yahoo.bullet.common.BulletError)16 BulletRecord (com.yahoo.bullet.record.BulletRecord)16 Arrays.asList (java.util.Arrays.asList)16 Clip (com.yahoo.bullet.result.Clip)14 Collections.singletonList (java.util.Collections.singletonList)12 QueryUtils.makeProjectionFilterQuery (com.yahoo.bullet.parsing.QueryUtils.makeProjectionFilterQuery)11 QueryUtils.makeRawFullQuery (com.yahoo.bullet.parsing.QueryUtils.makeRawFullQuery)11 Map (java.util.Map)11 AggregationUtils.makeAttributes (com.yahoo.bullet.parsing.AggregationUtils.makeAttributes)10 Window (com.yahoo.bullet.parsing.Window)10 Concept (com.yahoo.bullet.result.Meta.Concept)10 RecordBox (com.yahoo.bullet.result.RecordBox)10 ArrayList (java.util.ArrayList)10 IntStream (java.util.stream.IntStream)10