Search in sources :

Example 1 with ManualDistribution

use of com.yahoo.bullet.query.aggregations.ManualDistribution in project bullet-core by yahoo.

the class QuantileSketchingStrategyTest method makeDistribution.

public static QuantileSketchingStrategy makeDistribution(DistributionType type, List<Double> points) {
    ManualDistribution aggregation = new ManualDistribution("field", type, 20, points);
    BulletConfig configuration = makeConfiguration(10, 128);
    return new QuantileSketchingStrategy(aggregation, addMetadata(configuration, ALL_METADATA));
}
Also used : ManualDistribution(com.yahoo.bullet.query.aggregations.ManualDistribution) BulletConfig(com.yahoo.bullet.common.BulletConfig)

Example 2 with ManualDistribution

use of com.yahoo.bullet.query.aggregations.ManualDistribution 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

ManualDistribution (com.yahoo.bullet.query.aggregations.ManualDistribution)2 BulletConfig (com.yahoo.bullet.common.BulletConfig)1 LinearDistribution (com.yahoo.bullet.query.aggregations.LinearDistribution)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