Search in sources :

Example 1 with QuantileDigest

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

the class ApproximateLongPercentileArrayAggregations method weightedInput.

@InputFunction
public static void weightedInput(@AggregationState DigestAndPercentileArrayState state, @SqlType(StandardTypes.BIGINT) long value, @SqlType(StandardTypes.BIGINT) long weight, @SqlType("array(double)") Block percentilesArrayBlock) {
    initializePercentilesArray(state, percentilesArrayBlock);
    initializeDigest(state);
    QuantileDigest digest = state.getDigest();
    state.addMemoryUsage(-digest.estimatedInMemorySizeInBytes());
    digest.add(value, weight);
    state.addMemoryUsage(digest.estimatedInMemorySizeInBytes());
}
Also used : QuantileDigest(io.airlift.stats.QuantileDigest) InputFunction(com.facebook.presto.spi.function.InputFunction)

Example 2 with QuantileDigest

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

the class ApproximateLongPercentileArrayAggregations method initializeDigest.

private static void initializeDigest(@AggregationState DigestAndPercentileArrayState state) {
    QuantileDigest digest = state.getDigest();
    if (digest == null) {
        digest = new QuantileDigest(0.01);
        state.setDigest(digest);
        state.addMemoryUsage(digest.estimatedInMemorySizeInBytes());
    }
}
Also used : QuantileDigest(io.airlift.stats.QuantileDigest)

Example 3 with QuantileDigest

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

the class DigestAndPercentileArrayStateSerializer method deserialize.

@Override
public void deserialize(Block block, int index, DigestAndPercentileArrayState state) {
    SliceInput input = VARBINARY.getSlice(block, index).getInput();
    // read number of percentiles
    int numPercentiles = input.readInt();
    ImmutableList.Builder<Double> percentilesListBuilder = ImmutableList.builder();
    for (int i = 0; i < numPercentiles; i++) {
        percentilesListBuilder.add(input.readDouble());
    }
    state.setPercentiles(percentilesListBuilder.build());
    // read digest
    int length = input.readInt();
    state.setDigest(new QuantileDigest(input.readSlice(length)));
    state.addMemoryUsage(state.getDigest().estimatedInMemorySizeInBytes());
}
Also used : QuantileDigest(io.airlift.stats.QuantileDigest) ImmutableList(com.google.common.collect.ImmutableList) SliceInput(io.airlift.slice.SliceInput)

Example 4 with QuantileDigest

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

the class ApproximateDoublePercentileAggregations method output.

@OutputFunction(StandardTypes.DOUBLE)
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");
        DOUBLE.writeDouble(out, sortableLongToDouble(digest.getQuantile(percentile)));
    }
}
Also used : QuantileDigest(io.airlift.stats.QuantileDigest) OutputFunction(com.facebook.presto.spi.function.OutputFunction)

Example 5 with QuantileDigest

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

the class ApproximateDoublePercentileArrayAggregations method output.

@OutputFunction("array(double)")
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);
        DOUBLE.writeDouble(blockBuilder, sortableLongToDouble(digest.getQuantile(percentile)));
    }
    out.closeEntry();
}
Also used : QuantileDigest(io.airlift.stats.QuantileDigest) FloatingPointBitsConverterUtil.sortableLongToDouble(com.facebook.presto.operator.aggregation.FloatingPointBitsConverterUtil.sortableLongToDouble) BlockBuilder(com.facebook.presto.spi.block.BlockBuilder) OutputFunction(com.facebook.presto.spi.function.OutputFunction)

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