use of io.trino.operator.aggregation.state.LongDecimalWithOverflowAndLongStateSerializer in project trino by trinodb.
the class DecimalAverageAggregation method specialize.
@Override
public AggregationMetadata specialize(BoundSignature boundSignature) {
Type type = getOnlyElement(boundSignature.getArgumentTypes());
checkArgument(type instanceof DecimalType, "type must be Decimal");
MethodHandle inputFunction;
MethodHandle outputFunction;
Class<LongDecimalWithOverflowAndLongState> stateInterface = LongDecimalWithOverflowAndLongState.class;
LongDecimalWithOverflowAndLongStateSerializer stateSerializer = new LongDecimalWithOverflowAndLongStateSerializer();
if (((DecimalType) type).isShort()) {
inputFunction = SHORT_DECIMAL_INPUT_FUNCTION;
outputFunction = SHORT_DECIMAL_OUTPUT_FUNCTION;
} else {
inputFunction = LONG_DECIMAL_INPUT_FUNCTION;
outputFunction = LONG_DECIMAL_OUTPUT_FUNCTION;
}
outputFunction = outputFunction.bindTo(type);
return new AggregationMetadata(inputFunction, Optional.empty(), Optional.of(COMBINE_FUNCTION), outputFunction, ImmutableList.of(new AccumulatorStateDescriptor<>(stateInterface, stateSerializer, new LongDecimalWithOverflowAndLongStateFactory())));
}
Aggregations