Search in sources :

Example 6 with OutputFunction

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

the class ApproximateLongPercentileArrayAggregations method output.

@OutputFunction("array(bigint)")
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) {
        BIGINT.writeLong(blockBuilder, Math.round(value));
    }
    out.closeEntry();
}
Also used : TDigest(io.airlift.stats.TDigest) BlockBuilder(io.trino.spi.block.BlockBuilder) OutputFunction(io.trino.spi.function.OutputFunction)

Example 7 with OutputFunction

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

the class ApproximateRealPercentileArrayAggregations method output.

@OutputFunction("array(real)")
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) {
        REAL.writeLong(blockBuilder, floatToRawIntBits((float) value));
    }
    out.closeEntry();
}
Also used : TDigest(io.airlift.stats.TDigest) BlockBuilder(io.trino.spi.block.BlockBuilder) OutputFunction(io.trino.spi.function.OutputFunction)

Example 8 with OutputFunction

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

the class SpatialPartitioningInternalAggregateFunction method output.

@OutputFunction(StandardTypes.VARCHAR)
public static void output(SpatialPartitioningState state, BlockBuilder out) {
    if (state.getCount() == 0) {
        out.appendNull();
        return;
    }
    List<Rectangle> samples = state.getSamples();
    int partitionCount = state.getPartitionCount();
    int maxItemsPerNode = (samples.size() + partitionCount - 1) / partitionCount;
    Rectangle envelope = state.getExtent();
    // Add a small buffer on the right and upper sides
    Rectangle paddedExtent = new Rectangle(envelope.getXMin(), envelope.getYMin(), Math.nextUp(envelope.getXMax()), Math.nextUp(envelope.getYMax()));
    VARCHAR.writeString(out, KdbTreeUtils.toJson(buildKdbTree(maxItemsPerNode, paddedExtent, samples)));
}
Also used : Rectangle(io.trino.geospatial.Rectangle) OutputFunction(io.trino.spi.function.OutputFunction)

Example 9 with OutputFunction

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

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 entryBuilder = out.beginBlockEntry();
        for (Map.Entry<Double, Double> entry : value.entrySet()) {
            REAL.writeLong(entryBuilder, floatToRawIntBits(entry.getKey().floatValue()));
            REAL.writeLong(entryBuilder, floatToRawIntBits(entry.getValue().floatValue()));
        }
        out.closeEntry();
    }
}
Also used : Map(java.util.Map) BlockBuilder(io.trino.spi.block.BlockBuilder) OutputFunction(io.trino.spi.function.OutputFunction)

Example 10 with OutputFunction

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

the class VarcharApproximateMostFrequent method output.

@OutputFunction("map(varchar,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) -> {
            VarcharType.VARCHAR.writeSlice(entryBuilder, key);
            BigintType.BIGINT.writeLong(entryBuilder, value);
        });
        out.closeEntry();
    }
}
Also used : BlockBuilder(io.trino.spi.block.BlockBuilder) 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