Search in sources :

Example 11 with OutputFunction

use of io.trino.spi.function.OutputFunction in project trino by trinodb.

the class ApproximateDoublePercentileAggregations method output.

@OutputFunction(StandardTypes.DOUBLE)
public static void output(@AggregationState TDigestAndPercentileState state, BlockBuilder out) {
    TDigest 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, digest.valueAt(percentile));
    }
}
Also used : TDigest(io.airlift.stats.TDigest) OutputFunction(io.trino.spi.function.OutputFunction)

Example 12 with OutputFunction

use of io.trino.spi.function.OutputFunction in project trino by trinodb.

the class ApproximateDoublePercentileArrayAggregations method output.

@OutputFunction("array(double)")
public static void output(@AggregationState TDigestAndPercentileArrayState state, BlockBuilder out) {
    TDigest digest = state.getDigest();
    List<Double> percentiles = state.getPercentiles();
    if (percentiles == null || digest == null) {
        out.appendNull();
        return;
    }
    BlockBuilder blockBuilder = out.beginBlockEntry();
    List<Double> valuesAtPercentiles = valuesAtPercentiles(digest, percentiles);
    for (double value : valuesAtPercentiles) {
        DOUBLE.writeDouble(blockBuilder, value);
    }
    out.closeEntry();
}
Also used : TDigest(io.airlift.stats.TDigest) BlockBuilder(io.trino.spi.block.BlockBuilder) OutputFunction(io.trino.spi.function.OutputFunction)

Example 13 with OutputFunction

use of io.trino.spi.function.OutputFunction in project trino by trinodb.

the class ApproximateRealPercentileAggregations method output.

@OutputFunction(StandardTypes.REAL)
public static void output(@AggregationState TDigestAndPercentileState state, BlockBuilder out) {
    TDigest 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((float) digest.valueAt(percentile)));
    }
}
Also used : TDigest(io.airlift.stats.TDigest) OutputFunction(io.trino.spi.function.OutputFunction)

Example 14 with OutputFunction

use of io.trino.spi.function.OutputFunction in project trino by trinodb.

the class BigintApproximateMostFrequent method output.

@OutputFunction("map(bigint,bigint)")
public static void output(@AggregationState State state, BlockBuilder out) {
    if (state.get() == null) {
        out.appendNull();
    } else {
        BlockBuilder entryBuilder = out.beginBlockEntry();
        state.get().forEachBucket((key, value) -> {
            BigintType.BIGINT.writeLong(entryBuilder, key);
            BigintType.BIGINT.writeLong(entryBuilder, value);
        });
        out.closeEntry();
    }
}
Also used : BlockBuilder(io.trino.spi.block.BlockBuilder) OutputFunction(io.trino.spi.function.OutputFunction)

Example 15 with OutputFunction

use of io.trino.spi.function.OutputFunction in project trino by trinodb.

the class LegacyApproximateLongPercentileAggregations method output.

@OutputFunction(StandardTypes.BIGINT)
public static void output(@AggregationState QuantileDigestAndPercentileState 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(io.trino.spi.function.OutputFunction)

Aggregations

OutputFunction (io.trino.spi.function.OutputFunction)15 BlockBuilder (io.trino.spi.block.BlockBuilder)7 TDigest (io.airlift.stats.TDigest)6 QuantileDigest (io.airlift.stats.QuantileDigest)3 Map (java.util.Map)2 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Strings.emptyToNull (com.google.common.base.Strings.emptyToNull)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Iterables.getOnlyElement (com.google.common.collect.Iterables.getOnlyElement)1 MoreCollectors (com.google.common.collect.MoreCollectors)1 Logger (io.airlift.log.Logger)1 Rectangle (io.trino.geospatial.Rectangle)1 Signature (io.trino.metadata.Signature)1 ParametricFunctionHelpers.signatureWithName (io.trino.operator.ParametricFunctionHelpers.signatureWithName)1 ParametricImplementationsGroup (io.trino.operator.ParametricImplementationsGroup)1 Parser.parseImplementation (io.trino.operator.aggregation.AggregationImplementation.Parser.parseImplementation)1 FunctionsParserHelper (io.trino.operator.annotations.FunctionsParserHelper)1 FunctionsParserHelper.parseDescription (io.trino.operator.annotations.FunctionsParserHelper.parseDescription)1