Search in sources :

Example 1 with QuantileSketch

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

the class QuantileSketchingStrategy method getSketch.

private static QuantileSketch getSketch(Distribution aggregation, BulletConfig config) {
    int entries = config.getAs(BulletConfig.DISTRIBUTION_AGGREGATION_SKETCH_ENTRIES, Integer.class);
    int rounding = config.getAs(BulletConfig.DISTRIBUTION_AGGREGATION_GENERATED_POINTS_ROUNDING, Integer.class);
    int pointLimit = config.getAs(BulletConfig.DISTRIBUTION_AGGREGATION_MAX_POINTS, Integer.class);
    int maxPoints = Math.min(pointLimit, aggregation.getSize());
    BulletRecordProvider provider = config.getBulletRecordProvider();
    if (aggregation instanceof LinearDistribution) {
        int numberOfPoints = ((LinearDistribution) aggregation).getNumberOfPoints();
        return new QuantileSketch(entries, rounding, aggregation.getDistributionType(), Math.min(numberOfPoints, maxPoints), provider);
    } else if (aggregation instanceof ManualDistribution) {
        // Limit number of points
        List<Double> points = ((ManualDistribution) aggregation).getPoints();
        double[] cleanedPoints = points.stream().limit(maxPoints).mapToDouble(d -> d).toArray();
        return new QuantileSketch(entries, aggregation.getDistributionType(), cleanedPoints, provider);
    } else if (aggregation instanceof RegionDistribution) {
        RegionDistribution distribution = (RegionDistribution) aggregation;
        double start = distribution.getStart();
        double end = distribution.getEnd();
        double increment = distribution.getIncrement();
        return new QuantileSketch(entries, aggregation.getDistributionType(), getPoints(start, end, increment, maxPoints, rounding), provider);
    }
    throw new IllegalArgumentException("Unknown distribution input mode.");
}
Also used : RegionDistribution(com.yahoo.bullet.query.aggregations.RegionDistribution) LinearDistribution(com.yahoo.bullet.query.aggregations.LinearDistribution) BulletRecordProvider(com.yahoo.bullet.record.BulletRecordProvider) List(java.util.List) ManualDistribution(com.yahoo.bullet.query.aggregations.ManualDistribution) QuantileSketch(com.yahoo.bullet.querying.aggregations.sketches.QuantileSketch)

Aggregations

LinearDistribution (com.yahoo.bullet.query.aggregations.LinearDistribution)1 ManualDistribution (com.yahoo.bullet.query.aggregations.ManualDistribution)1 RegionDistribution (com.yahoo.bullet.query.aggregations.RegionDistribution)1 QuantileSketch (com.yahoo.bullet.querying.aggregations.sketches.QuantileSketch)1 BulletRecordProvider (com.yahoo.bullet.record.BulletRecordProvider)1 List (java.util.List)1