Search in sources :

Example 1 with LongDecimalWithOverflowAndLongStateSerializer

use of com.facebook.presto.operator.aggregation.state.LongDecimalWithOverflowAndLongStateSerializer in project presto by prestodb.

the class DecimalAverageAggregation method generateAggregation.

private static InternalAggregationFunction generateAggregation(Type type) {
    checkArgument(type instanceof DecimalType, "type must be Decimal");
    DynamicClassLoader classLoader = new DynamicClassLoader(DecimalAverageAggregation.class.getClassLoader());
    List<Type> inputTypes = ImmutableList.of(type);
    MethodHandle inputFunction;
    MethodHandle outputFunction;
    Class<? extends AccumulatorState> stateInterface = LongDecimalWithOverflowAndLongState.class;
    AccumulatorStateSerializer<?> 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;
    }
    inputFunction = inputFunction.bindTo(type);
    outputFunction = outputFunction.bindTo(type);
    AggregationMetadata metadata = new AggregationMetadata(generateAggregationName(NAME, type.getTypeSignature(), inputTypes.stream().map(Type::getTypeSignature).collect(toImmutableList())), createInputParameterMetadata(type), inputFunction, COMBINE_FUNCTION, outputFunction, stateInterface, stateSerializer, new LongDecimalWithOverflowAndLongStateFactory(), type);
    Type intermediateType = stateSerializer.getSerializedType();
    GenericAccumulatorFactoryBinder factory = AccumulatorCompiler.generateAccumulatorFactoryBinder(metadata, classLoader);
    return new InternalAggregationFunction(NAME, inputTypes, intermediateType, type, true, factory);
}
Also used : DynamicClassLoader(com.facebook.presto.bytecode.DynamicClassLoader) LongDecimalWithOverflowAndLongStateFactory(com.facebook.presto.operator.aggregation.state.LongDecimalWithOverflowAndLongStateFactory) LongDecimalWithOverflowAndLongState(com.facebook.presto.operator.aggregation.state.LongDecimalWithOverflowAndLongState) DecimalType(com.facebook.presto.spi.type.DecimalType) Type(com.facebook.presto.spi.type.Type) DecimalType(com.facebook.presto.spi.type.DecimalType) LongDecimalWithOverflowAndLongStateSerializer(com.facebook.presto.operator.aggregation.state.LongDecimalWithOverflowAndLongStateSerializer) MethodHandle(java.lang.invoke.MethodHandle)

Aggregations

DynamicClassLoader (com.facebook.presto.bytecode.DynamicClassLoader)1 LongDecimalWithOverflowAndLongState (com.facebook.presto.operator.aggregation.state.LongDecimalWithOverflowAndLongState)1 LongDecimalWithOverflowAndLongStateFactory (com.facebook.presto.operator.aggregation.state.LongDecimalWithOverflowAndLongStateFactory)1 LongDecimalWithOverflowAndLongStateSerializer (com.facebook.presto.operator.aggregation.state.LongDecimalWithOverflowAndLongStateSerializer)1 DecimalType (com.facebook.presto.spi.type.DecimalType)1 Type (com.facebook.presto.spi.type.Type)1 MethodHandle (java.lang.invoke.MethodHandle)1