Search in sources :

Example 11 with InputFunction

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

the class ApproximateCountDistinctAggregation 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") double value, @SqlType(StandardTypes.DOUBLE) double maxStandardError) {
    HyperLogLog hll = getOrCreateHyperLogLog(state, maxStandardError);
    state.addMemoryUsage(-hll.estimatedInMemorySize());
    long hash;
    try {
        hash = (long) methodHandle.invokeExact(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 12 with InputFunction

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

the class ApproximateDoublePercentileAggregations method input.

@InputFunction
public static void input(@AggregationState TDigestAndPercentileState state, @SqlType(StandardTypes.DOUBLE) double value, @SqlType(StandardTypes.DOUBLE) double percentile) {
    TDigest digest = state.getDigest();
    if (digest == null) {
        digest = new TDigest();
        state.setDigest(digest);
        state.addMemoryUsage(digest.estimatedInMemorySizeInBytes());
    }
    state.addMemoryUsage(-digest.estimatedInMemorySizeInBytes());
    digest.add(value);
    state.addMemoryUsage(digest.estimatedInMemorySizeInBytes());
    // use last percentile
    state.setPercentile(percentile);
}
Also used : TDigest(io.airlift.stats.TDigest) InputFunction(io.trino.spi.function.InputFunction)

Example 13 with InputFunction

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

the class ApproximateDoublePercentileAggregations method weightedInput.

@InputFunction
public static void weightedInput(@AggregationState TDigestAndPercentileState state, @SqlType(StandardTypes.DOUBLE) double value, @SqlType(StandardTypes.DOUBLE) double weight, @SqlType(StandardTypes.DOUBLE) double percentile) {
    verifyWeight(weight);
    TDigest digest = state.getDigest();
    if (digest == null) {
        digest = new TDigest();
        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 : TDigest(io.airlift.stats.TDigest) InputFunction(io.trino.spi.function.InputFunction)

Example 14 with InputFunction

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

the class ApproximateCountDistinctAggregation 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") long value, @SqlType(StandardTypes.DOUBLE) double maxStandardError) {
    HyperLogLog hll = getOrCreateHyperLogLog(state, maxStandardError);
    state.addMemoryUsage(-hll.estimatedInMemorySize());
    long hash;
    try {
        hash = (long) methodHandle.invokeExact(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 15 with InputFunction

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

the class ApproximateCountDistinctAggregation 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, @SqlType(StandardTypes.DOUBLE) double maxStandardError) {
    HyperLogLog hll = getOrCreateHyperLogLog(state, maxStandardError);
    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)

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