Search in sources :

Example 1 with LongDecimalWithOverflowAndLongStateSerializer

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())));
}
Also used : Type(io.trino.spi.type.Type) DecimalType(io.trino.spi.type.DecimalType) AccumulatorStateDescriptor(io.trino.operator.aggregation.AggregationMetadata.AccumulatorStateDescriptor) DecimalType(io.trino.spi.type.DecimalType) LongDecimalWithOverflowAndLongStateSerializer(io.trino.operator.aggregation.state.LongDecimalWithOverflowAndLongStateSerializer) LongDecimalWithOverflowAndLongStateFactory(io.trino.operator.aggregation.state.LongDecimalWithOverflowAndLongStateFactory) LongDecimalWithOverflowAndLongState(io.trino.operator.aggregation.state.LongDecimalWithOverflowAndLongState) MethodHandle(java.lang.invoke.MethodHandle)

Aggregations

AccumulatorStateDescriptor (io.trino.operator.aggregation.AggregationMetadata.AccumulatorStateDescriptor)1 LongDecimalWithOverflowAndLongState (io.trino.operator.aggregation.state.LongDecimalWithOverflowAndLongState)1 LongDecimalWithOverflowAndLongStateFactory (io.trino.operator.aggregation.state.LongDecimalWithOverflowAndLongStateFactory)1 LongDecimalWithOverflowAndLongStateSerializer (io.trino.operator.aggregation.state.LongDecimalWithOverflowAndLongStateSerializer)1 DecimalType (io.trino.spi.type.DecimalType)1 Type (io.trino.spi.type.Type)1 MethodHandle (java.lang.invoke.MethodHandle)1