Search in sources :

Example 11 with Meta

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

the class FrequentItemsSketchTest method testApproximateCounting.

@Test
public void testApproximateCounting() {
    FrequentItemsSketch sketch = new FrequentItemsSketch(ErrorType.NO_FALSE_POSITIVES, 32, 40);
    IntStream.range(0, 40).forEach(i -> sketch.update(String.valueOf(i)));
    IntStream.of(10, 20, 25, 30).forEach(i -> IntStream.range(0, i).forEach(j -> sketch.update(String.valueOf(i))));
    Clip result = sketch.getResult("meta", ALL_METADATA);
    Map<String, Object> metadata = (Map<String, Object>) result.getMeta().asMap().get("meta");
    Assert.assertEquals(metadata.size(), 5);
    Assert.assertTrue((Boolean) metadata.get("isEst"));
    Long error = (Long) metadata.get("error");
    List<BulletRecord> records = result.getRecords();
    // We should have our four frequent items
    Assert.assertTrue(records.size() >= 4);
    for (BulletRecord actual : records) {
        Assert.assertEquals(actual.fieldCount(), 2);
        Integer item = Integer.valueOf(actual.get(FrequentItemsSketch.ITEM_FIELD).toString());
        Long count = (Long) actual.get(FrequentItemsSketch.COUNT_FIELD);
        if (item == 10 || item == 20 || item == 25 || item == 30) {
            Assert.assertTrue(count >= item + 1);
            Assert.assertTrue(count <= item + 1 + error);
        } else {
            Assert.assertTrue(count >= 1);
            Assert.assertTrue(count <= 1 + error);
        }
    }
    Assert.assertEquals(sketch.getRecords(), result.getRecords());
    Assert.assertEquals(sketch.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)

Example 12 with Meta

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

the class QuerierTest method testExceptionWrapping.

@Test
public void testExceptionWrapping() {
    FailingScheme failingScheme = new FailingScheme(null, null, new BulletConfig());
    Querier querier = make(Querier.Mode.ALL, new Query());
    querier.setWindow(failingScheme);
    querier.consume(RecordBox.get().getRecord());
    querier.combine(new byte[0]);
    Assert.assertNull(querier.getData());
    Assert.assertNull(querier.getRecords());
    Meta meta = querier.getMetadata();
    Map<String, Object> actualMeta = meta.asMap();
    Assert.assertNotNull(actualMeta.get(Meta.ERROR_KEY));
    BulletError expected = BulletError.makeError("Getting metadata failure", Querier.TRY_AGAIN_LATER);
    Assert.assertEquals(actualMeta.get(Meta.ERROR_KEY), singletonList(expected));
    Clip actual = querier.getResult();
    Assert.assertNotNull(actual.getMeta());
    Assert.assertEquals(actual.getRecords().size(), 0);
    actualMeta = actual.getMeta().asMap();
    Assert.assertEquals(actualMeta.size(), 1);
    Assert.assertNotNull(actualMeta.get(Meta.ERROR_KEY));
    expected = BulletError.makeError("Getting result failure", Querier.TRY_AGAIN_LATER);
    Assert.assertEquals(actualMeta.get(Meta.ERROR_KEY), singletonList(expected));
    Assert.assertEquals(failingScheme.consumptionFailure, 1);
    Assert.assertEquals(failingScheme.combiningFailure, 1);
    Assert.assertEquals(failingScheme.serializingFailure, 1);
    Assert.assertEquals(failingScheme.aggregationFailure, 3);
}
Also used : Clip(com.yahoo.bullet.result.Clip) Meta(com.yahoo.bullet.result.Meta) 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) BulletError(com.yahoo.bullet.common.BulletError) BulletConfig(com.yahoo.bullet.common.BulletConfig) Test(org.testng.annotations.Test)

Example 13 with Meta

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

the class AdditiveTumblingTest method testMetadata.

@Test
public void testMetadata() throws Exception {
    long started = System.currentTimeMillis();
    AdditiveTumbling additiveTumbling = make(1, 1);
    Assert.assertFalse(additiveTumbling.initialize().isPresent());
    Thread.sleep(1);
    additiveTumbling.consume(RecordBox.get().getRecord());
    Assert.assertTrue(additiveTumbling.isClosed());
    Assert.assertTrue(additiveTumbling.isClosedForPartition());
    Assert.assertEquals(strategy.getMetadataCalls(), 0);
    Meta meta = additiveTumbling.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"), Tumbling.NAME);
    long closedTime = (Long) asMap.get("close");
    long shouldCloseTime = (Long) asMap.get("should_close");
    Assert.assertTrue(closedTime >= started);
    Assert.assertTrue(shouldCloseTime >= started);
    Assert.assertTrue(shouldCloseTime <= closedTime);
    Assert.assertEquals(strategy.getMetadataCalls(), 1);
    additiveTumbling.reset();
    meta = additiveTumbling.getMetadata();
    Assert.assertNotNull(meta);
    asMap = (Map<String, Object>) meta.asMap().get("window_stats");
    Assert.assertEquals(asMap.get("num"), 2L);
    Assert.assertEquals(asMap.get("name"), AdditiveTumbling.NAME);
    Assert.assertEquals(strategy.getMetadataCalls(), 2);
}
Also used : Meta(com.yahoo.bullet.result.Meta) Map(java.util.Map) Test(org.testng.annotations.Test)

Example 14 with Meta

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

the class BasicTest method testDisablingWindowMetadataDoesGetStrategyMetadata.

@Test
public void testDisablingWindowMetadataDoesGetStrategyMetadata() {
    // Metadata is enabled but no keys for the window metadata. Strategy metadata will be collected.
    addMetadata(config, Collections.emptyList());
    Basic basic = new Basic(strategy, null, config);
    Assert.assertEquals(strategy.getMetadataCalls(), 0);
    Meta meta = basic.getMetadata();
    Assert.assertNotNull(meta);
    Assert.assertTrue(meta.asMap().isEmpty());
    Assert.assertEquals(strategy.getMetadataCalls(), 1);
}
Also used : Meta(com.yahoo.bullet.result.Meta) Test(org.testng.annotations.Test)

Example 15 with Meta

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

the class BasicTest method testDisablingMetadataDoesNotGetStrategyMetadata.

@Test
public void testDisablingMetadataDoesNotGetStrategyMetadata() {
    // Metadata is disabled so Strategy metadata will not be collected.
    addMetadata(config, (List<Map.Entry<Meta.Concept, String>>) null);
    Basic basic = new Basic(strategy, null, config);
    Assert.assertEquals(strategy.getMetadataCalls(), 0);
    Meta meta = basic.getMetadata();
    Assert.assertNotNull(meta);
    Assert.assertTrue(meta.asMap().isEmpty());
    Assert.assertEquals(strategy.getMetadataCalls(), 0);
}
Also used : Meta(com.yahoo.bullet.result.Meta) 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