Search in sources :

Example 6 with Meta

use of com.yahoo.bullet.result.Meta in project bullet-core by yahoo.

the class ReactiveTest method testMetadata.

@Test
public void testMetadata() {
    Window window = makeReactiveWindow();
    Reactive reactive = new Reactive(strategy, window, config);
    Assert.assertFalse(reactive.initialize().isPresent());
    Assert.assertFalse(reactive.isClosed());
    Assert.assertFalse(reactive.isClosedForPartition());
    reactive.consume(RecordBox.get().getRecord());
    Assert.assertTrue(reactive.isClosed());
    Assert.assertTrue(reactive.isClosedForPartition());
    Assert.assertEquals(strategy.getMetadataCalls(), 0);
    long timeNow = System.currentTimeMillis();
    Meta meta = reactive.getMetadata();
    Assert.assertNotNull(meta);
    Map<String, Object> asMap = (Map<String, Object>) meta.asMap().get("window_stats");
    Assert.assertEquals(asMap.get("num"), 1L);
    Assert.assertEquals(asMap.get("name"), SlidingRecord.NAME);
    Assert.assertEquals(asMap.get("size"), 1);
    Assert.assertTrue(((Long) asMap.get("close")) >= timeNow);
    Assert.assertEquals(strategy.getMetadataCalls(), 1);
    reactive.reset();
    Assert.assertFalse(reactive.isClosed());
    Assert.assertFalse(reactive.isClosedForPartition());
    meta = reactive.getMetadata();
    Assert.assertNotNull(meta);
    asMap = (Map<String, Object>) meta.asMap().get("window_stats");
    Assert.assertEquals(asMap.get("num"), 2L);
    Assert.assertEquals(asMap.get("name"), SlidingRecord.NAME);
    Assert.assertEquals(asMap.get("size"), 0);
    Assert.assertTrue(((Long) asMap.get("close")) >= timeNow);
    Assert.assertEquals(strategy.getMetadataCalls(), 2);
    reactive.consume(RecordBox.get().getRecord());
    Assert.assertTrue(reactive.isClosed());
    Assert.assertTrue(reactive.isClosedForPartition());
    meta = reactive.getMetadata();
    Assert.assertNotNull(meta);
    asMap = (Map<String, Object>) meta.asMap().get("window_stats");
    Assert.assertEquals(asMap.get("num"), 2L);
    Assert.assertEquals(asMap.get("name"), SlidingRecord.NAME);
    Assert.assertEquals(asMap.get("size"), 1);
    Assert.assertTrue(((Long) asMap.get("close")) >= timeNow);
    Assert.assertEquals(strategy.getMetadataCalls(), 3);
}
Also used : Window(com.yahoo.bullet.parsing.Window) Meta(com.yahoo.bullet.result.Meta) Map(java.util.Map) Test(org.testng.annotations.Test)

Example 7 with Meta

use of com.yahoo.bullet.result.Meta in project bullet-storm by yahoo.

the class JoinBolt method emitRateLimitError.

private void emitRateLimitError(String id, Querier querier, RateLimitError error) {
    Metadata metadata = bufferedMetadata.get(id);
    Meta meta = error.makeMeta();
    Clip clip = querier.finish();
    clip.getMeta().merge(meta);
    emitResult(id, withSignal(metadata, Metadata.Signal.FAIL), clip);
    emitMetaSignal(id, Metadata.Signal.KILL);
    updateCount(rateExceededQueries, 1L);
    removeQuery(id);
}
Also used : Clip(com.yahoo.bullet.result.Clip) Meta(com.yahoo.bullet.result.Meta) Metadata(com.yahoo.bullet.pubsub.Metadata)

Example 8 with Meta

use of com.yahoo.bullet.result.Meta in project bullet-storm by yahoo.

the class JoinBoltTest method testUnknownConceptMetadata.

@Test
public void testUnknownConceptMetadata() {
    config = configWithRawMaxAndEmptyMeta();
    enableMetadataInConfig(config, Concept.QUERY_METADATA.getName(), "meta");
    enableMetadataInConfig(config, Concept.QUERY_ID.getName(), "id");
    enableMetadataInConfig(config, "foo", "bar");
    setup(new JoinBolt(config));
    Tuple query = TupleUtils.makeIDTuple(TupleClassifier.Type.QUERY_TUPLE, "42", "{}", EMPTY);
    bolt.execute(query);
    List<BulletRecord> sent = sendRawRecordTuplesTo(bolt, "42");
    Meta meta = new Meta();
    meta.add("meta", singletonMap("id", "42"));
    Tuple expected = TupleUtils.makeTuple(TupleClassifier.Type.RESULT_TUPLE, "42", Clip.of(sent).add(meta).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(collector.getAllEmittedTo(TopologyConstants.RESULT_STREAM).count(), 1);
    Assert.assertEquals(collector.getAllEmittedTo(TopologyConstants.FEEDBACK_STREAM).count(), 1);
}
Also used : Meta(com.yahoo.bullet.result.Meta) BulletRecord(com.yahoo.bullet.record.BulletRecord) Metadata(com.yahoo.bullet.pubsub.Metadata) 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 9 with Meta

use of com.yahoo.bullet.result.Meta in project bullet-storm by yahoo.

the class JoinBoltTest method testErrorInQueryWithoutMetadata.

@Test
public void testErrorInQueryWithoutMetadata() {
    Tuple query = TupleUtils.makeIDTuple(TupleClassifier.Type.QUERY_TUPLE, "42", "{\"aggregation\": {\"type\": \"garbage\"}}");
    bolt.execute(query);
    Assert.assertEquals(collector.getEmittedCount(), 1);
    BulletError expectedError = Aggregation.TYPE_NOT_SUPPORTED_ERROR;
    Meta expectedMetadata = Meta.of(expectedError);
    List<Object> expected = TupleUtils.makeTuple("42", Clip.of(expectedMetadata).asJSON(), FAILED).getValues();
    List<Object> actual = collector.getNthTupleEmittedTo(TopologyConstants.RESULT_STREAM, 1).get();
    Assert.assertTrue(isSameResult(actual, expected));
    Assert.assertEquals(collector.getAllEmittedTo(TopologyConstants.RESULT_STREAM).count(), 1);
    Assert.assertEquals(collector.getEmittedCount(), 1);
}
Also used : Meta(com.yahoo.bullet.result.Meta) JsonObject(com.google.gson.JsonObject) BulletError(com.yahoo.bullet.common.BulletError) 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 10 with Meta

use of com.yahoo.bullet.result.Meta in project bullet-core by yahoo.

the class FrequentItemsSketchTest method testUnioning.

@Test
public void testUnioning() {
    FrequentItemsSketch sketch = new FrequentItemsSketch(ErrorType.NO_FALSE_NEGATIVES, 32, 32);
    IntStream.range(0, 10).forEach(i -> IntStream.range(0, 10).forEach(j -> sketch.update(String.valueOf(i))));
    IntStream.range(10, 100).forEach(i -> sketch.update("bar"));
    FrequentItemsSketch another = new FrequentItemsSketch(ErrorType.NO_FALSE_NEGATIVES, 32, 32);
    another.update("foo");
    another.update("bar");
    another.update("baz");
    FrequentItemsSketch union = new FrequentItemsSketch(ErrorType.NO_FALSE_NEGATIVES, 32, 32);
    union.union(sketch.serialize());
    union.union(another.serialize());
    Clip result = union.getResult("meta", ALL_METADATA);
    Map<String, Object> metadata = (Map<String, Object>) result.getMeta().asMap().get("meta");
    Assert.assertEquals(metadata.size(), 5);
    Assert.assertFalse((Boolean) metadata.get("isEst"));
    List<BulletRecord> records = result.getRecords();
    Assert.assertEquals(records.size(), 13);
    for (BulletRecord actual : records) {
        String item = actual.get(FrequentItemsSketch.ITEM_FIELD).toString();
        Assert.assertEquals(actual.fieldCount(), 2);
        if ("bar".equals(item)) {
            Assert.assertEquals(actual.get(FrequentItemsSketch.COUNT_FIELD), 91L);
        } else if ("foo".equals(item) || "baz".equals(item)) {
            Assert.assertEquals(actual.get(FrequentItemsSketch.COUNT_FIELD), 1L);
        } else if (Integer.valueOf(item) < 10) {
            Assert.assertEquals(actual.get(FrequentItemsSketch.COUNT_FIELD), 10L);
        } else {
            Assert.fail("This should not be a case");
        }
    }
    Assert.assertEquals(union.getRecords(), records);
    Assert.assertEquals(union.getMetadata("meta", ALL_METADATA).asMap(), result.getMeta().asMap());
}
Also used : IntStream(java.util.stream.IntStream) List(java.util.List) Assert(org.testng.Assert) BulletRecord(com.yahoo.bullet.record.BulletRecord) SketchesArgumentException(com.yahoo.sketches.SketchesArgumentException) Meta(com.yahoo.bullet.result.Meta) Map(java.util.Map) Test(org.testng.annotations.Test) HashMap(java.util.HashMap) ErrorType(com.yahoo.sketches.frequencies.ErrorType) Clip(com.yahoo.bullet.result.Clip) Family(com.yahoo.sketches.Family) Clip(com.yahoo.bullet.result.Clip) BulletRecord(com.yahoo.bullet.record.BulletRecord) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.testng.annotations.Test)

Aggregations

Meta (com.yahoo.bullet.result.Meta)24 Test (org.testng.annotations.Test)20 Map (java.util.Map)11 Clip (com.yahoo.bullet.result.Clip)8 BulletRecord (com.yahoo.bullet.record.BulletRecord)7 CountDistinctTest (com.yahoo.bullet.aggregations.CountDistinctTest)6 DistributionTest (com.yahoo.bullet.aggregations.DistributionTest)6 GroupByTest (com.yahoo.bullet.aggregations.GroupByTest)6 TopKTest (com.yahoo.bullet.aggregations.TopKTest)6 HashMap (java.util.HashMap)6 Tuple (org.apache.storm.tuple.Tuple)6 BulletError (com.yahoo.bullet.common.BulletError)5 Family (com.yahoo.sketches.Family)5 SketchesArgumentException (com.yahoo.sketches.SketchesArgumentException)5 ErrorType (com.yahoo.sketches.frequencies.ErrorType)5 List (java.util.List)5 IntStream (java.util.stream.IntStream)5 Assert (org.testng.Assert)5 JsonObject (com.google.gson.JsonObject)4 Metadata (com.yahoo.bullet.pubsub.Metadata)3