use of io.trino.spi.function.OutputFunction in project trino by trinodb.
the class LegacyApproximateDoublePercentileAggregations method output.
@OutputFunction(StandardTypes.DOUBLE)
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");
DOUBLE.writeDouble(out, sortableLongToDouble(digest.getQuantile(percentile)));
}
}
use of io.trino.spi.function.OutputFunction in project trino by trinodb.
the class LegacyApproximateRealPercentileAggregations method output.
@OutputFunction(StandardTypes.REAL)
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");
REAL.writeLong(out, floatToRawIntBits(sortableIntToFloat((int) digest.getQuantile(percentile))));
}
}
use of io.trino.spi.function.OutputFunction in project trino by trinodb.
the class DoubleHistogramAggregation method output.
@OutputFunction("map(double,double)")
public static void output(@AggregationState 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()) {
DoubleType.DOUBLE.writeDouble(entryBuilder, entry.getKey());
DoubleType.DOUBLE.writeDouble(entryBuilder, entry.getValue());
}
out.closeEntry();
}
}
use of io.trino.spi.function.OutputFunction in project trino by trinodb.
the class AggregationFromAnnotationsParser method parseFunctionDefinitions.
public static List<ParametricAggregation> parseFunctionDefinitions(Class<?> aggregationDefinition) {
AggregationFunction aggregationAnnotation = aggregationDefinition.getAnnotation(AggregationFunction.class);
requireNonNull(aggregationAnnotation, "aggregationAnnotation is null");
ImmutableList.Builder<ParametricAggregation> functions = ImmutableList.builder();
// There must be a single state class and combine function
Class<? extends AccumulatorState> stateClass = getStateClass(aggregationDefinition);
Optional<Method> combineFunction = getCombineFunction(aggregationDefinition, stateClass);
// Each output function defines a new aggregation function
for (Method outputFunction : getOutputFunctions(aggregationDefinition, stateClass)) {
AggregationHeader header = parseHeader(aggregationDefinition, outputFunction);
if (header.isDecomposable()) {
checkArgument(combineFunction.isPresent(), "Decomposable method %s does not have a combine method", header.getName());
} else if (combineFunction.isPresent()) {
log.warn("Aggregation function %s is not decomposable, but has combine method", header.getName());
}
// Input functions can have either an exact signature, or generic/calculate signature
List<AggregationImplementation> exactImplementations = new ArrayList<>();
List<AggregationImplementation> nonExactImplementations = new ArrayList<>();
for (Method inputFunction : getInputFunctions(aggregationDefinition, stateClass)) {
Optional<Method> removeInputFunction = getRemoveInputFunction(aggregationDefinition, inputFunction);
AggregationImplementation implementation = parseImplementation(aggregationDefinition, header.getName(), inputFunction, removeInputFunction, outputFunction, combineFunction.filter(function -> header.isDecomposable()));
if (isGenericOrCalculated(implementation.getSignature())) {
exactImplementations.add(implementation);
} else {
nonExactImplementations.add(implementation);
}
}
// register a set functions for the canonical name, and each alias
functions.addAll(buildFunctions(header.getName(), header, stateClass, exactImplementations, nonExactImplementations));
for (String alias : getAliases(aggregationDefinition.getAnnotation(AggregationFunction.class), outputFunction)) {
functions.addAll(buildFunctions(alias, header, stateClass, exactImplementations, nonExactImplementations));
}
}
return functions.build();
}
use of io.trino.spi.function.OutputFunction in project trino by trinodb.
the class ApproximateLongPercentileAggregations method output.
@OutputFunction(StandardTypes.BIGINT)
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");
BIGINT.writeLong(out, Math.round(digest.valueAt(percentile)));
}
}
Aggregations