Search in sources :

Example 6 with QuantileDigest

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

the class ApproximateLongPercentileAggregations method weightedInput.

@InputFunction
public static void weightedInput(@AggregationState DigestAndPercentileState state, @SqlType(StandardTypes.BIGINT) long value, @SqlType(StandardTypes.BIGINT) long weight, @SqlType(StandardTypes.DOUBLE) double percentile, @SqlType(StandardTypes.DOUBLE) double accuracy) {
    checkWeight(weight);
    QuantileDigest digest = state.getDigest();
    if (digest == null) {
        if (accuracy > 0 && accuracy < 1) {
            digest = new QuantileDigest(accuracy);
        } else {
            throw new IllegalArgumentException("Percentile accuracy must be strictly between 0 and 1");
        }
        state.setDigest(digest);
        state.addMemoryUsage(digest.estimatedInMemorySizeInBytes());
    }
    state.addMemoryUsage(-digest.estimatedInMemorySizeInBytes());
    digest.add(value, weight);
    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 7 with QuantileDigest

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

the class DigestAndPercentileStateSerializer method deserialize.

@Override
public void deserialize(Block block, int index, DigestAndPercentileState state) {
    SliceInput input = VARBINARY.getSlice(block, index).getInput();
    // read percentile
    state.setPercentile(input.readDouble());
    // read digest
    int length = input.readInt();
    QuantileDigest digest = new QuantileDigest(input.readSlice(length));
    state.setDigest(digest);
    state.addMemoryUsage(state.getDigest().estimatedInMemorySizeInBytes());
}
Also used : QuantileDigest(io.airlift.stats.QuantileDigest) SliceInput(io.airlift.slice.SliceInput)

Example 8 with QuantileDigest

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

the class ApproximateLongPercentileArrayAggregations method input.

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

Example 9 with QuantileDigest

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

the class ApproximateLongPercentileArrayAggregations method combine.

@CombineFunction
public static void combine(@AggregationState DigestAndPercentileArrayState state, DigestAndPercentileArrayState otherState) {
    QuantileDigest otherDigest = otherState.getDigest();
    QuantileDigest digest = state.getDigest();
    if (digest == null) {
        state.setDigest(otherDigest);
        state.addMemoryUsage(otherDigest.estimatedInMemorySizeInBytes());
    } else {
        state.addMemoryUsage(-digest.estimatedInMemorySizeInBytes());
        digest.merge(otherDigest);
        state.addMemoryUsage(digest.estimatedInMemorySizeInBytes());
    }
    state.setPercentiles(otherState.getPercentiles());
}
Also used : QuantileDigest(io.airlift.stats.QuantileDigest) CombineFunction(com.facebook.presto.spi.function.CombineFunction)

Example 10 with QuantileDigest

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

the class ApproximateLongPercentileArrayAggregations method output.

@OutputFunction("array(bigint)")
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);
        BIGINT.writeLong(blockBuilder, 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)

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