Search in sources :

Example 16 with QuantileDigest

use of com.facebook.airlift.stats.QuantileDigest in project presto by prestodb.

the class TestQuantileDigestAggregationFunction method getExpectedValueLongs.

private Object getExpectedValueLongs(double maxError, long... values) {
    if (values.length == 0) {
        return null;
    }
    QuantileDigest qdigest = new QuantileDigest(maxError);
    Arrays.stream(values).forEach(qdigest::add);
    return new SqlVarbinary(qdigest.serialize().getBytes());
}
Also used : QuantileDigest(com.facebook.airlift.stats.QuantileDigest) SqlVarbinary(com.facebook.presto.common.type.SqlVarbinary)

Example 17 with QuantileDigest

use of com.facebook.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(com.facebook.airlift.stats.QuantileDigest) BlockBuilder(com.facebook.presto.common.block.BlockBuilder) OutputFunction(com.facebook.presto.spi.function.OutputFunction)

Example 18 with QuantileDigest

use of com.facebook.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(com.facebook.airlift.stats.QuantileDigest) CombineFunction(com.facebook.presto.spi.function.CombineFunction)

Example 19 with QuantileDigest

use of com.facebook.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(com.facebook.airlift.stats.QuantileDigest) BlockBuilder(com.facebook.presto.common.block.BlockBuilder) OutputFunction(com.facebook.presto.spi.function.OutputFunction)

Example 20 with QuantileDigest

use of com.facebook.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(com.facebook.airlift.stats.QuantileDigest) CombineFunction(com.facebook.presto.spi.function.CombineFunction)

Aggregations

QuantileDigest (com.facebook.airlift.stats.QuantileDigest)29 Test (org.testng.annotations.Test)8 BlockBuilder (com.facebook.presto.common.block.BlockBuilder)7 OutputFunction (com.facebook.presto.spi.function.OutputFunction)6 SqlVarbinary (com.facebook.presto.common.type.SqlVarbinary)4 Description (com.facebook.presto.spi.function.Description)4 ScalarFunction (com.facebook.presto.spi.function.ScalarFunction)4 SqlType (com.facebook.presto.spi.function.SqlType)4 CombineFunction (com.facebook.presto.spi.function.CombineFunction)2 SliceInput (io.airlift.slice.SliceInput)2 Block (com.facebook.presto.common.block.Block)1 DoubleType (com.facebook.presto.common.type.DoubleType)1 Type (com.facebook.presto.common.type.Type)1 FloatingPointBitsConverterUtil.sortableLongToDouble (com.facebook.presto.operator.aggregation.FloatingPointBitsConverterUtil.sortableLongToDouble)1 SqlNullable (com.facebook.presto.spi.function.SqlNullable)1 ImmutableList (com.google.common.collect.ImmutableList)1