Search in sources :

Example 31 with Clip

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

the class FrequentItemsSketch method getResult.

@Override
public Clip getResult(String metaKey, Map<String, String> conceptKeys) {
    Clip data = super.getResult(metaKey, conceptKeys);
    data.add(getRecords());
    return data;
}
Also used : Clip(com.yahoo.bullet.result.Clip)

Example 32 with Clip

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

the class QuerierTest method testTimes.

@Test
public void testTimes() {
    BulletConfig defaults = new BulletConfig();
    Map<String, String> names = (Map<String, String>) defaults.get(BulletConfig.RESULT_METADATA_METRICS);
    long startTime = System.currentTimeMillis();
    Querier querier = make(Querier.Mode.ALL, "", "{'aggregation' : {}}", emptyMap());
    Map<String, Object> meta = querier.getMetadata().asMap();
    Assert.assertEquals(meta.size(), 2);
    Map<String, Object> queryMeta = (Map<String, Object>) meta.get(names.get(Meta.Concept.QUERY_METADATA.getName()));
    Map<String, Object> windowMeta = (Map<String, Object>) meta.get(names.get(Meta.Concept.WINDOW_METADATA.getName()));
    long creationTime = ((Number) queryMeta.get(names.get(Meta.Concept.QUERY_RECEIVE_TIME.getName()))).longValue();
    long emitTime = ((Number) windowMeta.get(names.get(Meta.Concept.WINDOW_EMIT_TIME.getName()))).longValue();
    long endTime = System.currentTimeMillis();
    Assert.assertTrue(creationTime >= startTime && creationTime <= endTime);
    Assert.assertTrue(emitTime >= startTime && emitTime <= endTime);
    Clip finalResult = querier.finish();
    Assert.assertNotNull(finalResult);
    Assert.assertTrue(finalResult.getRecords().isEmpty());
    meta = finalResult.getMeta().asMap();
    queryMeta = (Map<String, Object>) meta.get(names.get(Meta.Concept.QUERY_METADATA.getName()));
    windowMeta = (Map<String, Object>) meta.get(names.get(Meta.Concept.WINDOW_METADATA.getName()));
    creationTime = ((Number) queryMeta.get(names.get(Meta.Concept.QUERY_RECEIVE_TIME.getName()))).longValue();
    emitTime = ((Number) windowMeta.get(names.get(Meta.Concept.WINDOW_EMIT_TIME.getName()))).longValue();
    long finishTime = ((Number) queryMeta.get(names.get(Meta.Concept.QUERY_FINISH_TIME.getName()))).longValue();
    endTime = System.currentTimeMillis();
    Assert.assertTrue(creationTime >= startTime && creationTime <= finishTime);
    Assert.assertTrue(emitTime >= startTime && emitTime <= finishTime);
    Assert.assertTrue(finishTime <= endTime);
}
Also used : Clip(com.yahoo.bullet.result.Clip) Map(java.util.Map) Collections.singletonMap(java.util.Collections.singletonMap) Collections.emptyMap(java.util.Collections.emptyMap) BulletConfig(com.yahoo.bullet.common.BulletConfig) Test(org.testng.annotations.Test)

Example 33 with Clip

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

the class QuerierTest method testDisabledQueryMeta.

@Test
public void testDisabledQueryMeta() {
    BulletConfig defaults = new BulletConfig();
    defaults.set(BulletConfig.RESULT_METADATA_METRICS, emptyMap());
    Querier querier = make(Querier.Mode.ALL, "", "{'aggregation' : {}}", defaults);
    Assert.assertTrue(querier.getMetadata().asMap().isEmpty());
    Clip result = querier.finish();
    Assert.assertNotNull(result);
    Assert.assertTrue(result.getRecords().isEmpty());
    Assert.assertTrue(result.getMeta().asMap().isEmpty());
}
Also used : Clip(com.yahoo.bullet.result.Clip) BulletConfig(com.yahoo.bullet.common.BulletConfig) Test(org.testng.annotations.Test)

Example 34 with Clip

use of com.yahoo.bullet.result.Clip 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 35 with Clip

use of com.yahoo.bullet.result.Clip 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

Clip (com.yahoo.bullet.result.Clip)66 Test (org.testng.annotations.Test)55 BulletRecord (com.yahoo.bullet.record.BulletRecord)48 Map (java.util.Map)43 List (java.util.List)33 IntStream (java.util.stream.IntStream)33 Assert (org.testng.Assert)33 BulletConfig (com.yahoo.bullet.common.BulletConfig)32 HashMap (java.util.HashMap)30 BulletError (com.yahoo.bullet.common.BulletError)29 TestHelpers.addMetadata (com.yahoo.bullet.TestHelpers.addMetadata)28 Aggregation (com.yahoo.bullet.parsing.Aggregation)28 AggregationUtils.makeAttributes (com.yahoo.bullet.parsing.AggregationUtils.makeAttributes)28 Concept (com.yahoo.bullet.result.Meta.Concept)28 RecordBox (com.yahoo.bullet.result.RecordBox)28 Family (com.yahoo.sketches.Family)28 Arrays.asList (java.util.Arrays.asList)28 Optional (java.util.Optional)28 Pair (org.apache.commons.lang3.tuple.Pair)28 HashSet (java.util.HashSet)23