Search in sources :

Example 1 with Meta

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

the class FrequentItemsSketchTest method testExactCounting.

@Test
public void testExactCounting() {
    FrequentItemsSketch sketch = new FrequentItemsSketch(ErrorType.NO_FALSE_NEGATIVES, 32, 15);
    IntStream.range(0, 10).forEach(i -> IntStream.range(0, 10).forEach(j -> sketch.update(String.valueOf(i))));
    sketch.update("foo");
    IntStream.range(10, 100).forEach(i -> sketch.update("bar"));
    sketch.update("baz");
    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.assertFalse((Boolean) metadata.get("isEst"));
    Assert.assertEquals((String) metadata.get("family"), Family.FREQUENCY.getFamilyName());
    Assert.assertNull(metadata.get("size"));
    Assert.assertEquals(metadata.get("error"), 0L);
    Assert.assertEquals(metadata.get("n"), 192L);
    Assert.assertEquals(metadata.get("actives"), 13);
    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), 90L);
        } 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(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 2 with Meta

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

the class FrequentItemsSketchTest method testResetting.

@Test
public void testResetting() {
    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");
    sketch.union(another.serialize());
    Clip result = sketch.getResult("meta", ALL_METADATA);
    Map<String, Object> metadata = (Map<String, Object>) result.getMeta().asMap().get("meta");
    Assert.assertFalse((Boolean) metadata.get("isEst"));
    Assert.assertEquals(result.getRecords().size(), 13);
    Assert.assertEquals(sketch.getRecords(), result.getRecords());
    Assert.assertEquals(sketch.getMetadata("meta", ALL_METADATA).asMap(), result.getMeta().asMap());
    sketch.reset();
    result = sketch.getResult("meta", ALL_METADATA);
    metadata = (Map<String, Object>) result.getMeta().asMap().get("meta");
    Assert.assertEquals((String) metadata.get("family"), Family.FREQUENCY.getFamilyName());
    Assert.assertNull(metadata.get("size"));
    Assert.assertEquals(metadata.get("error"), 0L);
    Assert.assertEquals(metadata.get("n"), 0L);
    Assert.assertEquals(metadata.get("actives"), 0);
    Assert.assertFalse((Boolean) metadata.get("isEst"));
    List<BulletRecord> records = result.getRecords();
    Assert.assertEquals(records.size(), 0);
    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 3 with Meta

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

the class FrequentItemsSketchTest method testSizeLimiting.

@Test
public void testSizeLimiting() {
    FrequentItemsSketch sketch = new FrequentItemsSketch(ErrorType.NO_FALSE_NEGATIVES, 32, 10);
    // For i from 1 to 13, update the sketch i times
    IntStream.range(1, 13).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.assertFalse((Boolean) metadata.get("isEst"));
    List<BulletRecord> records = result.getRecords();
    Assert.assertEquals(records.size(), 10);
    for (BulletRecord actual : records) {
        Assert.assertEquals(actual.fieldCount(), 2);
        Integer item = Integer.valueOf(actual.get(FrequentItemsSketch.ITEM_FIELD).toString());
        // 1, 2 had the lowest and since our size is 10, we should have not seen them
        Assert.assertTrue(item > 2 && item < 13);
        Assert.assertEquals(actual.get(FrequentItemsSketch.COUNT_FIELD), Long.valueOf(item));
    }
    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 4 with Meta

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

the class Scheme method getMetadata.

/**
 * Return any {@link Meta} for this windowing scheme and the {@link Strategy}.
 *
 * @return A non-null Meta object.
 */
@Override
public Meta getMetadata() {
    Meta meta = new Meta();
    boolean shouldMeta = config.getAs(BulletConfig.RESULT_METADATA_ENABLE, Boolean.class);
    if (shouldMeta) {
        String key = getMetaKey();
        if (key != null) {
            meta.add(key, getMetadata(metadataKeys));
        }
        meta.merge(aggregation.getMetadata());
    }
    return meta;
}
Also used : Meta(com.yahoo.bullet.result.Meta)

Example 5 with Meta

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

the class Querier method getResultMetadata.

private Meta getResultMetadata() {
    String metaKey = getMetaKey();
    if (metaKey == null) {
        return null;
    }
    Map<String, Object> meta = new HashMap<>();
    addIfNonNull(meta, metaKeys, Concept.QUERY_ID, runningQuery::getId);
    addIfNonNull(meta, metaKeys, Concept.QUERY_BODY, runningQuery::toString);
    addIfNonNull(meta, metaKeys, Concept.QUERY_RECEIVE_TIME, runningQuery::getStartTime);
    return new Meta().add(metaKey, meta);
}
Also used : Meta(com.yahoo.bullet.result.Meta) HashMap(java.util.HashMap)

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