Search in sources :

Example 6 with OutputFunction

use of com.facebook.presto.spi.function.OutputFunction 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 7 with OutputFunction

use of com.facebook.presto.spi.function.OutputFunction 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 8 with OutputFunction

use of com.facebook.presto.spi.function.OutputFunction in project presto by prestodb.

the class RealHistogramAggregation method output.

@OutputFunction("map(real,real)")
public static void output(@AggregationState DoubleHistogramAggregation.State state, BlockBuilder out) {
    if (state.get() == null) {
        out.appendNull();
    } else {
        Map<Double, Double> value = state.get().getBuckets();
        BlockBuilder blockBuilder = REAL.createBlockBuilder(new BlockBuilderStatus(), value.size() * 2);
        for (Map.Entry<Double, Double> entry : value.entrySet()) {
            REAL.writeLong(blockBuilder, floatToRawIntBits(entry.getKey().floatValue()));
            REAL.writeLong(blockBuilder, floatToRawIntBits(entry.getValue().floatValue()));
        }
        Block block = blockBuilder.build();
        out.writeObject(block);
        out.closeEntry();
    }
}
Also used : Block(com.facebook.presto.spi.block.Block) Map(java.util.Map) BlockBuilder(com.facebook.presto.spi.block.BlockBuilder) BlockBuilderStatus(com.facebook.presto.spi.block.BlockBuilderStatus) OutputFunction(com.facebook.presto.spi.function.OutputFunction)

Aggregations

OutputFunction (com.facebook.presto.spi.function.OutputFunction)8 QuantileDigest (io.airlift.stats.QuantileDigest)6 BlockBuilder (com.facebook.presto.spi.block.BlockBuilder)5 Block (com.facebook.presto.spi.block.Block)2 BlockBuilderStatus (com.facebook.presto.spi.block.BlockBuilderStatus)2 Map (java.util.Map)2 FloatingPointBitsConverterUtil.sortableLongToDouble (com.facebook.presto.operator.aggregation.FloatingPointBitsConverterUtil.sortableLongToDouble)1