Search in sources :

Example 6 with COUNT_FIELD

use of com.yahoo.bullet.querying.aggregations.sketches.QuantileSketch.COUNT_FIELD in project bullet-core by yahoo.

the class QuantileSketchingStrategyTest method testCasting.

@Test
public void testCasting() {
    QuantileSketchingStrategy distribution = makeDistribution(DistributionType.PMF, Collections.singletonList(50.0));
    IntStream.range(0, 25).mapToObj(String::valueOf).map(s -> RecordBox.get().add("field", s).getRecord()).forEach(distribution::consume);
    distribution.consume(RecordBox.get().add("field", "garbage").getRecord());
    distribution.consume(RecordBox.get().add("field", "1.0 garbage").getRecord());
    IntStream.range(50, 100).mapToDouble(i -> i).mapToObj(d -> RecordBox.get().add("field", d).getRecord()).forEach(distribution::consume);
    Clip result = distribution.getResult();
    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(), 2);
    BulletRecord expectedA = RecordBox.get().add(RANGE_FIELD, NEGATIVE_INFINITY_START + SEPARATOR + 50.0 + END_EXCLUSIVE).add(COUNT_FIELD, 25.0).add(PROBABILITY_FIELD, 1.0 / 3).getRecord();
    BulletRecord expectedB = RecordBox.get().add(RANGE_FIELD, START_INCLUSIVE + 50.0 + SEPARATOR + POSITIVE_INFINITY_END).add(COUNT_FIELD, 50.0).add(PROBABILITY_FIELD, 2.0 / 3).getRecord();
    Assert.assertEquals(records.get(0), expectedA);
    Assert.assertEquals(records.get(1), expectedB);
    Assert.assertEquals(distribution.getRecords(), result.getRecords());
    Assert.assertEquals(distribution.getMetadata().asMap(), result.getMeta().asMap());
}
Also used : LinearDistribution(com.yahoo.bullet.query.aggregations.LinearDistribution) IntStream(java.util.stream.IntStream) Arrays(java.util.Arrays) ManualDistribution(com.yahoo.bullet.query.aggregations.ManualDistribution) RegionDistribution(com.yahoo.bullet.query.aggregations.RegionDistribution) START_INCLUSIVE(com.yahoo.bullet.querying.aggregations.sketches.QuantileSketch.START_INCLUSIVE) END_EXCLUSIVE(com.yahoo.bullet.querying.aggregations.sketches.QuantileSketch.END_EXCLUSIVE) PROBABILITY_FIELD(com.yahoo.bullet.querying.aggregations.sketches.QuantileSketch.PROBABILITY_FIELD) Concept(com.yahoo.bullet.result.Meta.Concept) Test(org.testng.annotations.Test) RecordBox(com.yahoo.bullet.result.RecordBox) NEGATIVE_INFINITY_START(com.yahoo.bullet.querying.aggregations.sketches.QuantileSketch.NEGATIVE_INFINITY_START) Clip(com.yahoo.bullet.result.Clip) Family(com.yahoo.sketches.Family) HashSet(java.util.HashSet) Pair(org.apache.commons.lang3.tuple.Pair) Assert(org.testng.Assert) VALUE_FIELD(com.yahoo.bullet.querying.aggregations.sketches.QuantileSketch.VALUE_FIELD) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) Distribution(com.yahoo.bullet.query.aggregations.Distribution) POSITIVE_INFINITY_END(com.yahoo.bullet.querying.aggregations.sketches.QuantileSketch.POSITIVE_INFINITY_END) BulletRecord(com.yahoo.bullet.record.BulletRecord) DoublesSketch(com.yahoo.sketches.quantiles.DoublesSketch) QUANTILE_FIELD(com.yahoo.bullet.querying.aggregations.sketches.QuantileSketch.QUANTILE_FIELD) Set(java.util.Set) Collectors(java.util.stream.Collectors) List(java.util.List) TestHelpers.assertApproxEquals(com.yahoo.bullet.TestHelpers.assertApproxEquals) RANGE_FIELD(com.yahoo.bullet.querying.aggregations.sketches.QuantileSketch.RANGE_FIELD) TestHelpers.addMetadata(com.yahoo.bullet.TestHelpers.addMetadata) BulletConfig(com.yahoo.bullet.common.BulletConfig) DistributionType(com.yahoo.bullet.query.aggregations.DistributionType) COUNT_FIELD(com.yahoo.bullet.querying.aggregations.sketches.QuantileSketch.COUNT_FIELD) SEPARATOR(com.yahoo.bullet.querying.aggregations.sketches.QuantileSketch.SEPARATOR) Collections(java.util.Collections) Clip(com.yahoo.bullet.result.Clip) BulletRecord(com.yahoo.bullet.record.BulletRecord) Map(java.util.Map) Test(org.testng.annotations.Test)

Aggregations

TestHelpers.addMetadata (com.yahoo.bullet.TestHelpers.addMetadata)6 TestHelpers.assertApproxEquals (com.yahoo.bullet.TestHelpers.assertApproxEquals)6 BulletConfig (com.yahoo.bullet.common.BulletConfig)6 Distribution (com.yahoo.bullet.query.aggregations.Distribution)6 DistributionType (com.yahoo.bullet.query.aggregations.DistributionType)6 LinearDistribution (com.yahoo.bullet.query.aggregations.LinearDistribution)6 ManualDistribution (com.yahoo.bullet.query.aggregations.ManualDistribution)6 RegionDistribution (com.yahoo.bullet.query.aggregations.RegionDistribution)6 COUNT_FIELD (com.yahoo.bullet.querying.aggregations.sketches.QuantileSketch.COUNT_FIELD)6 END_EXCLUSIVE (com.yahoo.bullet.querying.aggregations.sketches.QuantileSketch.END_EXCLUSIVE)6 NEGATIVE_INFINITY_START (com.yahoo.bullet.querying.aggregations.sketches.QuantileSketch.NEGATIVE_INFINITY_START)6 POSITIVE_INFINITY_END (com.yahoo.bullet.querying.aggregations.sketches.QuantileSketch.POSITIVE_INFINITY_END)6 PROBABILITY_FIELD (com.yahoo.bullet.querying.aggregations.sketches.QuantileSketch.PROBABILITY_FIELD)6 QUANTILE_FIELD (com.yahoo.bullet.querying.aggregations.sketches.QuantileSketch.QUANTILE_FIELD)6 RANGE_FIELD (com.yahoo.bullet.querying.aggregations.sketches.QuantileSketch.RANGE_FIELD)6 SEPARATOR (com.yahoo.bullet.querying.aggregations.sketches.QuantileSketch.SEPARATOR)6 START_INCLUSIVE (com.yahoo.bullet.querying.aggregations.sketches.QuantileSketch.START_INCLUSIVE)6 VALUE_FIELD (com.yahoo.bullet.querying.aggregations.sketches.QuantileSketch.VALUE_FIELD)6 BulletRecord (com.yahoo.bullet.record.BulletRecord)6 Clip (com.yahoo.bullet.result.Clip)6