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());
}
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());
}
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());
}
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());
}
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);
}
Aggregations