Search in sources :

Example 1 with LongDecimalWithOverflowStateSerializer

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

the class DecimalSumAggregation method generateAggregation.

private static InternalAggregationFunction generateAggregation(Type inputType, Type outputType) {
    checkArgument(inputType instanceof DecimalType, "type must be Decimal");
    DynamicClassLoader classLoader = new DynamicClassLoader(DecimalSumAggregation.class.getClassLoader());
    List<Type> inputTypes = ImmutableList.of(inputType);
    MethodHandle inputFunction;
    Class<? extends AccumulatorState> stateInterface = LongDecimalWithOverflowState.class;
    AccumulatorStateSerializer<?> stateSerializer = new LongDecimalWithOverflowStateSerializer();
    if (((DecimalType) inputType).isShort()) {
        inputFunction = SHORT_DECIMAL_INPUT_FUNCTION;
    } else {
        inputFunction = LONG_DECIMAL_INPUT_FUNCTION;
    }
    AggregationMetadata metadata = new AggregationMetadata(generateAggregationName(NAME, outputType.getTypeSignature(), inputTypes.stream().map(Type::getTypeSignature).collect(toImmutableList())), createInputParameterMetadata(inputType), inputFunction, COMBINE_FUNCTION, LONG_DECIMAL_OUTPUT_FUNCTION, ImmutableList.of(new AccumulatorStateDescriptor(stateInterface, stateSerializer, new LongDecimalWithOverflowStateFactory())), outputType);
    Type intermediateType = stateSerializer.getSerializedType();
    GenericAccumulatorFactoryBinder factory = AccumulatorCompiler.generateAccumulatorFactoryBinder(metadata, classLoader);
    return new InternalAggregationFunction(NAME, inputTypes, ImmutableList.of(intermediateType), outputType, true, false, factory);
}
Also used : DynamicClassLoader(com.facebook.presto.bytecode.DynamicClassLoader) AccumulatorStateDescriptor(com.facebook.presto.operator.aggregation.AggregationMetadata.AccumulatorStateDescriptor) LongDecimalWithOverflowState(com.facebook.presto.operator.aggregation.state.LongDecimalWithOverflowState) DecimalType(com.facebook.presto.common.type.DecimalType) Type(com.facebook.presto.common.type.Type) LongDecimalWithOverflowStateFactory(com.facebook.presto.operator.aggregation.state.LongDecimalWithOverflowStateFactory) DecimalType(com.facebook.presto.common.type.DecimalType) LongDecimalWithOverflowStateSerializer(com.facebook.presto.operator.aggregation.state.LongDecimalWithOverflowStateSerializer) MethodHandle(java.lang.invoke.MethodHandle)

Aggregations

DynamicClassLoader (com.facebook.presto.bytecode.DynamicClassLoader)1 DecimalType (com.facebook.presto.common.type.DecimalType)1 Type (com.facebook.presto.common.type.Type)1 AccumulatorStateDescriptor (com.facebook.presto.operator.aggregation.AggregationMetadata.AccumulatorStateDescriptor)1 LongDecimalWithOverflowState (com.facebook.presto.operator.aggregation.state.LongDecimalWithOverflowState)1 LongDecimalWithOverflowStateFactory (com.facebook.presto.operator.aggregation.state.LongDecimalWithOverflowStateFactory)1 LongDecimalWithOverflowStateSerializer (com.facebook.presto.operator.aggregation.state.LongDecimalWithOverflowStateSerializer)1 MethodHandle (java.lang.invoke.MethodHandle)1