当前位置: 首页>>代码示例>>Java>>正文


Java Clip类代码示例

本文整理汇总了Java中com.yahoo.bullet.result.Clip的典型用法代码示例。如果您正苦于以下问题:Java Clip类的具体用法?Java Clip怎么用?Java Clip使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Clip类属于com.yahoo.bullet.result包,在下文中一共展示了Clip类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testSizeLimiting

import com.yahoo.bullet.result.Clip; //导入依赖的package包/类
@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));
    }
}
 
开发者ID:yahoo,项目名称:bullet-core,代码行数:21,代码来源:FrequentItemsSketchTest.java

示例2: testNoDataQuantileDistribution

import com.yahoo.bullet.result.Clip; //导入依赖的package包/类
@Test
public void testNoDataQuantileDistribution() {
    QuantileSketch sketch = new QuantileSketch(64, DistributionType.QUANTILE, new double[]{ 0, 0.3, 1 });

    Clip result = sketch.getResult("meta", ALL_METADATA);
    Map<String, Object> metadata = (Map<String, Object>) result.getMeta().asMap().get("meta");
    Assert.assertEquals(metadata.size(), 7);

    Assert.assertFalse((Boolean) metadata.get("isEst"));
    Assert.assertEquals(metadata.get("n"), 0L);
    Assert.assertEquals(metadata.get("min"), Double.POSITIVE_INFINITY);
    Assert.assertEquals(metadata.get("max"), Double.NEGATIVE_INFINITY);

    List<BulletRecord> records = result.getRecords();
    Assert.assertEquals(records.size(), 3);

    BulletRecord expectedA = RecordBox.get().add(QUANTILE_FIELD, 0.0).add(VALUE_FIELD, Double.POSITIVE_INFINITY)
                                            .getRecord();
    BulletRecord expectedB = RecordBox.get().add(QUANTILE_FIELD, 0.3).add(VALUE_FIELD, Double.NaN).getRecord();
    BulletRecord expectedC = RecordBox.get().add(QUANTILE_FIELD, 1.0).add(VALUE_FIELD, Double.NEGATIVE_INFINITY)
                                            .getRecord();
    Assert.assertEquals(records.get(0), expectedA);
    Assert.assertEquals(records.get(1), expectedB);
    Assert.assertEquals(records.get(2), expectedC);
}
 
开发者ID:yahoo,项目名称:bullet-core,代码行数:26,代码来源:QuantileSketchTest.java

示例3: testRounding

import com.yahoo.bullet.result.Clip; //导入依赖的package包/类
@Test
public void testRounding() {
    QuantileSketch sketch = new QuantileSketch(64, 6, DistributionType.CDF, 10);

    IntStream.range(0, 30).forEach(i -> sketch.update(i % 10));
    IntStream.range(0, 30).forEach(i -> sketch.update(i % 3));

    Clip result = sketch.getResult(null, null);

    Set<String> actualRangeEnds = result.getRecords().stream().map(r -> (String) r.get(RANGE_FIELD))
                                                              .map(QuantileSketchTest::getEnd)
                                                              .collect(Collectors.toSet());
    Set<String> expectedRangeEnds = new HashSet<>(Arrays.asList("0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "6.0",
                                                                "7.0", "8.0", "9.0", POSITIVE_INFINITY));
    Assert.assertEquals(actualRangeEnds, expectedRangeEnds);

}
 
开发者ID:yahoo,项目名称:bullet-core,代码行数:18,代码来源:QuantileSketchTest.java

示例4: testUpdatingForApproximateResult

import com.yahoo.bullet.result.Clip; //导入依赖的package包/类
@Test
public void testUpdatingForApproximateResult() {
    ThetaSketch sketch = new ThetaSketch(ResizeFactor.X4, Family.ALPHA, 1.0f, 512);
    IntStream.range(0, 1024).forEach(i -> sketch.update(String.valueOf(i)));

    Map<String, String> metaKeys = new HashMap<>();
    metaKeys.put(Concept.ESTIMATED_RESULT.getName(), "isEst");

    Clip result = sketch.getResult("meta", metaKeys);

    Map<String, Object> actualMeta = result.getMeta().asMap();
    Assert.assertTrue(actualMeta.containsKey("meta"));
    Map<String, Object> stats = (Map<String, Object>) actualMeta.get("meta");
    Assert.assertEquals(stats.size(), 1);
    Assert.assertTrue((Boolean) stats.get("isEst"));

    Assert.assertEquals(result.getRecords().size(), 1);
    double actual = (Double) result.getRecords().get(0).get(ThetaSketch.COUNT_FIELD);
    // We better be at least 50% accurate with 512 entries and 1024 uniques
    Assert.assertTrue(actual > 512);
    Assert.assertTrue(actual < 1536);
}
 
开发者ID:yahoo,项目名称:bullet-core,代码行数:23,代码来源:ThetaSketchTest.java

示例5: testNewNamingOfResult

import com.yahoo.bullet.result.Clip; //导入依赖的package包/类
@Test
public void testNewNamingOfResult() {
    BulletConfig config = makeConfiguration(4, 1024);
    CountDistinct countDistinct = makeCountDistinct(config, makeAttributes("myCount"), asList("field"),
                                                    Pair.of(Concept.SKETCH_METADATA, "stats"),
                                                    Pair.of(Concept.ESTIMATED_RESULT, "est"));

    IntStream.range(0, 1000).mapToObj(i -> RecordBox.get().add("field", i).getRecord())
                            .forEach(countDistinct::consume);

    Clip clip = countDistinct.getAggregation();

    Map<String, Object> meta = clip.getMeta().asMap();
    Assert.assertEquals(meta.size(), 1);
    Assert.assertTrue(meta.containsKey("stats"));
    Map<String, Object> stats = (Map<String, Object>) meta.get("stats");
    Assert.assertEquals(stats.size(), 1);
    Assert.assertFalse((Boolean) stats.get("est"));

    Assert.assertEquals(clip.getRecords().size(), 1);
    BulletRecord actual = clip.getRecords().get(0);
    BulletRecord expected = RecordBox.get().add("myCount", 1000.0).getRecord();
    Assert.assertEquals(actual, expected);
}
 
开发者ID:yahoo,项目名称:bullet-core,代码行数:25,代码来源:CountDistinctTest.java

示例6: testMultipleFieldsCountDistinctAmbiguity

import com.yahoo.bullet.result.Clip; //导入依赖的package包/类
@Test
public void testMultipleFieldsCountDistinctAmbiguity() {
    BulletConfig config = makeConfiguration(4, 512);

    String s = BulletConfig.DEFAULT_AGGREGATION_COMPOSITE_FIELD_SEPARATOR;
    CountDistinct countDistinct = makeCountDistinct(config, makeAttributes("myCount"), asList("fieldA", "fieldB"));
    BulletRecord first = RecordBox.get().add("fieldA", s).add("fieldB", s + s).getRecord();
    BulletRecord second = RecordBox.get().add("fieldA", s + s).add("fieldB", s).getRecord();
    // first and second will look the same to the Sketch. third will not
    BulletRecord third = RecordBox.get().add("fieldA", s + s).add("fieldB", s + s).getRecord();

    countDistinct.consume(first);
    countDistinct.consume(second);
    countDistinct.consume(third);

    Clip clip = countDistinct.getAggregation();
    Assert.assertEquals(clip.getRecords().size(), 1);
    BulletRecord actual = clip.getRecords().get(0);
    BulletRecord expected = RecordBox.get().add("myCount", 2.0).getRecord();
    Assert.assertEquals(actual, expected);
}
 
开发者ID:yahoo,项目名称:bullet-core,代码行数:22,代码来源:CountDistinctTest.java

示例7: testRounding

import com.yahoo.bullet.result.Clip; //导入依赖的package包/类
@Test
public void testRounding() {
    Distribution distribution = makeDistribution(DistributionType.QUANTILE, 20, 6, 0.0, 1.0, 0.1);

    IntStream.range(0, 10).mapToDouble(i -> (i * 0.1)).mapToObj(d -> RecordBox.get().add("field", d).getRecord())
                           .forEach(distribution::consume);

    Clip result = distribution.getAggregation();

    Map<String, Object> metadata = (Map<String, Object>) result.getMeta().asMap().get("meta");
    Assert.assertEquals(metadata.size(), 7);
    Assert.assertFalse((Boolean) metadata.get("isEst"));

    List<BulletRecord> records = result.getRecords();
    Assert.assertEquals(records.size(), 11);
    Set<String> actualQuantilePoints = records.stream().map(r -> r.get(QUANTILE_FIELD).toString())
                                                       .collect(Collectors.toSet());
    Set<String> expectedQuantilePoints = new HashSet<>(Arrays.asList("0.0", "0.1", "0.2", "0.3", "0.4", "0.5", "0.6",
                                                                     "0.7", "0.8", "0.9", "1.0"));
    Assert.assertEquals(actualQuantilePoints, expectedQuantilePoints);
}
 
开发者ID:yahoo,项目名称:bullet-core,代码行数:22,代码来源:DistributionTest.java

示例8: testExactTopKSizeLimiting

import com.yahoo.bullet.result.Clip; //导入依赖的package包/类
@Test
public void testExactTopKSizeLimiting() {
    TopK topK = makeTopK(ErrorType.NO_FALSE_POSITIVES, singletonList("A"), "cnt", 64, 2, null);
    IntStream.range(0, 20).mapToObj(i -> RecordBox.get().add("A", i).getRecord()).forEach(topK::consume);
    IntStream.range(0, 20).mapToObj(i -> RecordBox.get().add("A", 108.1).getRecord()).forEach(topK::consume);
    IntStream.range(0, 100).mapToObj(i -> RecordBox.get().add("A", 42L).getRecord()).forEach(topK::consume);

    Clip result = topK.getAggregation();

    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(), 2);

    BulletRecord expectedA = RecordBox.get().add("A", "42").add("cnt", 100L).getRecord();
    BulletRecord expectedB = RecordBox.get().add("A", "108.1").add("cnt", 20L).getRecord();
    Assert.assertEquals(records.get(0), expectedA);
    Assert.assertEquals(records.get(1), expectedB);
}
 
开发者ID:yahoo,项目名称:bullet-core,代码行数:22,代码来源:TopKTest.java

示例9: testNullAttributes

import com.yahoo.bullet.result.Clip; //导入依赖的package包/类
@Test
public void testNullAttributes() {
    TopK topK = makeTopK(makeConfiguration(ErrorType.NO_FALSE_NEGATIVES, 32), null, singletonMap("A", "foo"), 16, null);
    IntStream.range(0, 16).mapToObj(i -> RecordBox.get().add("A", i).getRecord()).forEach(topK::consume);

    Clip result = topK.getAggregation();
    Assert.assertNull(result.getMeta().asMap().get("meta"));

    List<BulletRecord> records = result.getRecords();
    Assert.assertEquals(records.size(), 16);
    for (BulletRecord actual : records) {
        Assert.assertEquals(actual.fieldCount(), 2);
        int fieldA = Integer.valueOf(actual.get("foo").toString());
        Assert.assertTrue(fieldA < 16);
        Assert.assertEquals(actual.get(TopK.DEFAULT_NEW_NAME), 1L);
    }
}
 
开发者ID:yahoo,项目名称:bullet-core,代码行数:18,代码来源:TopKTest.java

示例10: testRenaming

import com.yahoo.bullet.result.Clip; //导入依赖的package包/类
@Test
public void testRenaming() {
    HashMap<String, String> fields = new HashMap<>();
    fields.put("A", "foo");
    fields.put("fieldB", "");

    TopK topK = makeTopK(makeConfiguration(ErrorType.NO_FALSE_NEGATIVES, -1), null, fields, 16, null);
    IntStream.range(0, 16).mapToObj(i -> RecordBox.get().add("A", i).add("fieldB", 32 - i).getRecord())
                          .forEach(topK::consume);

    Clip result = topK.getAggregation();
    Assert.assertNull(result.getMeta().asMap().get("meta"));

    List<BulletRecord> records = result.getRecords();
    Assert.assertEquals(records.size(), 16);
    for (BulletRecord actual : records) {
        Assert.assertEquals(actual.fieldCount(), 3);
        int fieldA = Integer.valueOf(actual.get("foo").toString());
        int fieldB = Integer.valueOf(actual.get("fieldB").toString());
        Assert.assertTrue(fieldA < 16);
        Assert.assertTrue(fieldB > 16);
        Assert.assertEquals(actual.get(TopK.DEFAULT_NEW_NAME), 1L);
    }
}
 
开发者ID:yahoo,项目名称:bullet-core,代码行数:25,代码来源:TopKTest.java

示例11: testQueryExpiry

import com.yahoo.bullet.result.Clip; //导入依赖的package包/类
@Test
public void testQueryExpiry() {
    bolt = ComponentUtils.prepare(new ExpiringJoinBolt(), collector);

    Tuple query = TupleUtils.makeIDTuple(TupleType.Type.QUERY_TUPLE, "42", "{}", METADATA);
    bolt.execute(query);

    Tuple tick = TupleUtils.makeTuple(TupleType.Type.TICK_TUPLE);
    bolt.execute(tick);

    List<BulletRecord> sent = sendRawRecordTuplesTo(bolt, "42", Aggregation.DEFAULT_SIZE - 1);

    Tuple expected = TupleUtils.makeTuple(TupleType.Type.JOIN_TUPLE, "42", Clip.of(sent).asJSON(), METADATA);

    // Should cause an expiry and starts buffering the query for the query tickout
    bolt.execute(tick);
    // We need to tick the default query tickout to make the query emit
    for (int i = 0; i < JoinBolt.DEFAULT_QUERY_TICKOUT - 1; ++i) {
        bolt.execute(tick);
        Assert.assertFalse(collector.wasTupleEmitted(expected));
    }
    bolt.execute(tick);

    Assert.assertTrue(collector.wasNthEmitted(expected, 1));
    Assert.assertEquals(collector.getAllEmitted().count(), 1);
}
 
开发者ID:yahoo,项目名称:bullet-storm,代码行数:27,代码来源:JoinBoltTest.java

示例12: testQueryIdentifierMetadata

import com.yahoo.bullet.result.Clip; //导入依赖的package包/类
@Test
public void testQueryIdentifierMetadata() {
    Map<String, Object> config = new HashMap<>();
    enableMetadataInConfig(config, Concept.QUERY_ID.getName(), "id");
    setup(config, new JoinBolt());

    Tuple query = TupleUtils.makeIDTuple(TupleType.Type.QUERY_TUPLE, "42", "{}", METADATA);
    bolt.execute(query);

    List<BulletRecord> sent = sendRawRecordTuplesTo(bolt, "42");

    Metadata meta = new Metadata();
    meta.add("id", "42");
    Tuple expected = TupleUtils.makeTuple(TupleType.Type.JOIN_TUPLE, "42", Clip.of(sent).add(meta).asJSON(), METADATA);
    Assert.assertTrue(collector.wasNthEmitted(expected, 1));
    Assert.assertEquals(collector.getAllEmitted().count(), 1);
}
 
开发者ID:yahoo,项目名称:bullet-storm,代码行数:18,代码来源:JoinBoltTest.java

示例13: testUnknownConceptMetadata

import com.yahoo.bullet.result.Clip; //导入依赖的package包/类
@Test
public void testUnknownConceptMetadata() {
    Map<String, Object> config = new HashMap<>();
    enableMetadataInConfig(config, Concept.QUERY_ID.getName(), "id");
    enableMetadataInConfig(config, "foo", "bar");
    setup(config, new JoinBolt());

    Tuple query = TupleUtils.makeIDTuple(TupleType.Type.QUERY_TUPLE, "42", "{}", METADATA);
    bolt.execute(query);

    List<BulletRecord> sent = sendRawRecordTuplesTo(bolt, "42");

    Metadata meta = new Metadata();
    meta.add("id", "42");
    Tuple expected = TupleUtils.makeTuple(TupleType.Type.JOIN_TUPLE, "42", Clip.of(sent).add(meta).asJSON(), METADATA);
    Assert.assertTrue(collector.wasNthEmitted(expected, 1));
    Assert.assertEquals(collector.getAllEmitted().count(), 1);
}
 
开发者ID:yahoo,项目名称:bullet-storm,代码行数:19,代码来源:JoinBoltTest.java

示例14: testUnhandledExceptionErrorEmitted

import com.yahoo.bullet.result.Clip; //导入依赖的package包/类
@Test
public void testUnhandledExceptionErrorEmitted() {
    // An empty query should throw an null-pointer exception which should be caught in JoinBolt
    // and an error should be emitted
    Tuple query = TupleUtils.makeIDTuple(TupleType.Type.QUERY_TUPLE, "42", "", METADATA);
    bolt.execute(query);

    sendRawRecordTuplesTo(bolt, "42");

    Assert.assertEquals(collector.getAllEmitted().count(), 1);

    String error = Error.GENERIC_JSON_ERROR + ":\n\nNullPointerException: ";
    Error expectedError = Error.of(error, singletonList(Error.GENERIC_JSON_RESOLUTION));
    Metadata expectedMetadata = Metadata.of(expectedError);
    List<Object> expected = TupleUtils.makeTuple("42", Clip.of(expectedMetadata).asJSON(), METADATA).getValues();
    List<Object> actual = collector.getNthTupleEmittedTo(JoinBolt.JOIN_STREAM, 1).get();
    Assert.assertEquals(actual, expected);
}
 
开发者ID:yahoo,项目名称:bullet-storm,代码行数:19,代码来源:JoinBoltTest.java

示例15: getResult

import com.yahoo.bullet.result.Clip; //导入依赖的package包/类
@Override
public Clip getResult(String metaKey, Map<String, String> conceptKeys) {
    Clip result = super.getResult(metaKey, conceptKeys);

    SketchIterator<GroupDataSummary> iterator = merged.iterator();
    for (int count = 0; iterator.next() && count < maxSize; count++) {
        GroupData data = iterator.getSummary().getData();
        result.add(data.getAsBulletRecord());
    }
    return result;
}
 
开发者ID:yahoo,项目名称:bullet-core,代码行数:12,代码来源:TupleSketch.java


注:本文中的com.yahoo.bullet.result.Clip类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。