Search in sources :

Example 11 with QuantileDigest

use of io.airlift.stats.QuantileDigest in project presto by prestodb.

the class ApproximateRealPercentileAggregations method output.

@OutputFunction(StandardTypes.REAL)
public static void output(@AggregationState DigestAndPercentileState state, BlockBuilder out) {
    QuantileDigest digest = state.getDigest();
    double percentile = state.getPercentile();
    if (digest == null || digest.getCount() == 0.0) {
        out.appendNull();
    } else {
        checkState(percentile != -1.0, "Percentile is missing");
        checkCondition(0 <= percentile && percentile <= 1, INVALID_FUNCTION_ARGUMENT, "Percentile must be between 0 and 1");
        REAL.writeLong(out, floatToRawIntBits(sortableIntToFloat((int) digest.getQuantile(percentile))));
    }
}
Also used : QuantileDigest(io.airlift.stats.QuantileDigest) OutputFunction(com.facebook.presto.spi.function.OutputFunction)

Example 12 with QuantileDigest

use of io.airlift.stats.QuantileDigest in project presto by prestodb.

the class ApproximateRealPercentileArrayAggregations method output.

@OutputFunction("array(real)")
public static void output(@AggregationState DigestAndPercentileArrayState state, BlockBuilder out) {
    QuantileDigest digest = state.getDigest();
    List<Double> percentiles = state.getPercentiles();
    if (percentiles == null || digest == null) {
        out.appendNull();
        return;
    }
    BlockBuilder blockBuilder = out.beginBlockEntry();
    for (int i = 0; i < percentiles.size(); i++) {
        Double percentile = percentiles.get(i);
        REAL.writeLong(blockBuilder, floatToRawIntBits(sortableIntToFloat((int) digest.getQuantile(percentile))));
    }
    out.closeEntry();
}
Also used : QuantileDigest(io.airlift.stats.QuantileDigest) BlockBuilder(com.facebook.presto.spi.block.BlockBuilder) OutputFunction(com.facebook.presto.spi.function.OutputFunction)

Example 13 with QuantileDigest

use of io.airlift.stats.QuantileDigest in project presto by prestodb.

the class ApproximateLongPercentileAggregations method output.

@OutputFunction(StandardTypes.BIGINT)
public static void output(@AggregationState DigestAndPercentileState state, BlockBuilder out) {
    QuantileDigest digest = state.getDigest();
    double percentile = state.getPercentile();
    if (digest == null || digest.getCount() == 0.0) {
        out.appendNull();
    } else {
        checkState(percentile != -1.0, "Percentile is missing");
        checkCondition(0 <= percentile && percentile <= 1, INVALID_FUNCTION_ARGUMENT, "Percentile must be between 0 and 1");
        BIGINT.writeLong(out, digest.getQuantile(percentile));
    }
}
Also used : QuantileDigest(io.airlift.stats.QuantileDigest) OutputFunction(com.facebook.presto.spi.function.OutputFunction)

Example 14 with QuantileDigest

use of io.airlift.stats.QuantileDigest in project presto by prestodb.

the class ApproximateLongPercentileAggregations method input.

@InputFunction
public static void input(@AggregationState DigestAndPercentileState state, @SqlType(StandardTypes.BIGINT) long value, @SqlType(StandardTypes.DOUBLE) double percentile) {
    QuantileDigest digest = state.getDigest();
    if (digest == null) {
        digest = new QuantileDigest(0.01);
        state.setDigest(digest);
        state.addMemoryUsage(digest.estimatedInMemorySizeInBytes());
    }
    state.addMemoryUsage(-digest.estimatedInMemorySizeInBytes());
    digest.add(value);
    state.addMemoryUsage(digest.estimatedInMemorySizeInBytes());
    // use last percentile
    state.setPercentile(percentile);
}
Also used : QuantileDigest(io.airlift.stats.QuantileDigest) InputFunction(com.facebook.presto.spi.function.InputFunction)

Example 15 with QuantileDigest

use of io.airlift.stats.QuantileDigest in project presto by prestodb.

the class ApproximateLongPercentileAggregations method combine.

@CombineFunction
public static void combine(@AggregationState DigestAndPercentileState state, DigestAndPercentileState otherState) {
    QuantileDigest input = otherState.getDigest();
    QuantileDigest previous = state.getDigest();
    if (previous == null) {
        state.setDigest(input);
        state.addMemoryUsage(input.estimatedInMemorySizeInBytes());
    } else {
        state.addMemoryUsage(-previous.estimatedInMemorySizeInBytes());
        previous.merge(input);
        state.addMemoryUsage(previous.estimatedInMemorySizeInBytes());
    }
    state.setPercentile(otherState.getPercentile());
}
Also used : QuantileDigest(io.airlift.stats.QuantileDigest) CombineFunction(com.facebook.presto.spi.function.CombineFunction)

Aggregations

QuantileDigest (io.airlift.stats.QuantileDigest)15 OutputFunction (com.facebook.presto.spi.function.OutputFunction)6 InputFunction (com.facebook.presto.spi.function.InputFunction)4 BlockBuilder (com.facebook.presto.spi.block.BlockBuilder)3 CombineFunction (com.facebook.presto.spi.function.CombineFunction)2 SliceInput (io.airlift.slice.SliceInput)2 FloatingPointBitsConverterUtil.sortableLongToDouble (com.facebook.presto.operator.aggregation.FloatingPointBitsConverterUtil.sortableLongToDouble)1 ImmutableList (com.google.common.collect.ImmutableList)1