Search in sources :

Example 16 with InputFunction

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

the class ApproximateDoublePercentileArrayAggregations method input.

@InputFunction
public static void input(@AggregationState TDigestAndPercentileArrayState state, @SqlType(StandardTypes.DOUBLE) double value, @SqlType("array(double)") Block percentilesArrayBlock) {
    initializePercentilesArray(state, percentilesArrayBlock);
    initializeDigest(state);
    TDigest digest = state.getDigest();
    state.addMemoryUsage(-digest.estimatedInMemorySizeInBytes());
    digest.add(value);
    state.addMemoryUsage(digest.estimatedInMemorySizeInBytes());
}
Also used : TDigest(io.airlift.stats.TDigest) InputFunction(io.trino.spi.function.InputFunction)

Example 17 with InputFunction

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

the class ApproximateSetAggregation method input.

@InputFunction
public static void input(@AggregationState HyperLogLogState state, @SqlType(StandardTypes.BIGINT) long value) {
    HyperLogLog hll = getOrCreateHyperLogLog(state);
    state.addMemoryUsage(-hll.estimatedInMemorySize());
    hll.add(value);
    state.addMemoryUsage(hll.estimatedInMemorySize());
}
Also used : HyperLogLog(io.airlift.stats.cardinality.HyperLogLog) InputFunction(io.trino.spi.function.InputFunction)

Example 18 with InputFunction

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

the class ApproximateSetGenericAggregation method input.

@InputFunction
public static void input(@AggregationState HyperLogLogState state, @SqlType("BOOLEAN") boolean value) {
    HyperLogLog hll = getOrCreateHyperLogLog(state);
    state.addMemoryUsage(-hll.estimatedInMemorySize());
    hll.addHash(value ? 19144387141682250L : -2447670524089286488L);
    state.addMemoryUsage(hll.estimatedInMemorySize());
}
Also used : HyperLogLog(io.airlift.stats.cardinality.HyperLogLog) InputFunction(io.trino.spi.function.InputFunction)

Example 19 with InputFunction

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

the class ApproximateSetGenericAggregation method input.

@InputFunction
@TypeParameter("T")
public static void input(@OperatorDependency(operator = XX_HASH_64, argumentTypes = "T", convention = @Convention(arguments = NEVER_NULL, result = FAIL_ON_NULL)) MethodHandle methodHandle, @AggregationState HyperLogLogState state, @SqlType("T") Object value) {
    HyperLogLog hll = getOrCreateHyperLogLog(state);
    state.addMemoryUsage(-hll.estimatedInMemorySize());
    long hash;
    try {
        hash = (long) methodHandle.invoke(value);
    } catch (Throwable t) {
        throw internalError(t);
    }
    hll.addHash(hash);
    state.addMemoryUsage(hll.estimatedInMemorySize());
}
Also used : HyperLogLog(io.airlift.stats.cardinality.HyperLogLog) TypeParameter(io.trino.spi.function.TypeParameter) InputFunction(io.trino.spi.function.InputFunction)

Example 20 with InputFunction

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

the class LegacyApproximateLongPercentileAggregations method weightedInput.

// This function is deprecated. It uses QuantileDigest while other 'approx_percentile' functions use TDigest. TDigest does not accept the accuracy parameter.
@Deprecated
@Description("(DEPRECATED) Use approx_percentile(x, weight, percentile) instead")
@InputFunction
public static void weightedInput(@AggregationState QuantileDigestAndPercentileState state, @SqlType(StandardTypes.BIGINT) long value, @SqlType(StandardTypes.DOUBLE) double weight, @SqlType(StandardTypes.DOUBLE) double percentile, @SqlType(StandardTypes.DOUBLE) double accuracy) {
    checkCondition(weight > 0, INVALID_FUNCTION_ARGUMENT, "percentile weight must be > 0");
    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) Description(io.trino.spi.function.Description) InputFunction(io.trino.spi.function.InputFunction)

Aggregations

InputFunction (io.trino.spi.function.InputFunction)20 HyperLogLog (io.airlift.stats.cardinality.HyperLogLog)11 TDigest (io.airlift.stats.TDigest)6 TypeParameter (io.trino.spi.function.TypeParameter)6 Envelope (com.esri.core.geometry.Envelope)1 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 QuantileDigest (io.airlift.stats.QuantileDigest)1 Rectangle (io.trino.geospatial.Rectangle)1 GeometrySerde.deserializeEnvelope (io.trino.geospatial.serde.GeometrySerde.deserializeEnvelope)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