Search in sources :

Example 1 with BlockStateSerializer

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

the class AbstractMinMaxAggregationFunction method generateAggregation.

protected InternalAggregationFunction generateAggregation(Type type, MethodHandle compareMethodHandle) {
    DynamicClassLoader classLoader = new DynamicClassLoader(AbstractMinMaxAggregationFunction.class.getClassLoader());
    List<Type> inputTypes = ImmutableList.of(type);
    MethodHandle inputFunction;
    MethodHandle combineFunction;
    MethodHandle outputFunction;
    Class<? extends AccumulatorState> stateInterface;
    AccumulatorStateSerializer<?> stateSerializer;
    if (type.getJavaType() == long.class) {
        stateInterface = NullableLongState.class;
        stateSerializer = StateCompiler.generateStateSerializer(stateInterface, classLoader);
        inputFunction = LONG_INPUT_FUNCTION;
        combineFunction = LONG_COMBINE_FUNCTION;
        outputFunction = LONG_OUTPUT_FUNCTION;
    } else if (type.getJavaType() == double.class) {
        stateInterface = NullableDoubleState.class;
        stateSerializer = StateCompiler.generateStateSerializer(stateInterface, classLoader);
        inputFunction = DOUBLE_INPUT_FUNCTION;
        combineFunction = DOUBLE_COMBINE_FUNCTION;
        outputFunction = DOUBLE_OUTPUT_FUNCTION;
    } else if (type.getJavaType() == Slice.class) {
        stateInterface = SliceState.class;
        stateSerializer = StateCompiler.generateStateSerializer(stateInterface, classLoader);
        inputFunction = SLICE_INPUT_FUNCTION;
        combineFunction = SLICE_COMBINE_FUNCTION;
        outputFunction = SLICE_OUTPUT_FUNCTION;
    } else if (type.getJavaType() == boolean.class) {
        stateInterface = NullableBooleanState.class;
        stateSerializer = StateCompiler.generateStateSerializer(stateInterface, classLoader);
        inputFunction = BOOLEAN_INPUT_FUNCTION;
        combineFunction = BOOLEAN_COMBINE_FUNCTION;
        outputFunction = BOOLEAN_OUTPUT_FUNCTION;
    } else {
        stateInterface = BlockState.class;
        stateSerializer = new BlockStateSerializer(type);
        inputFunction = BLOCK_INPUT_FUNCTION;
        combineFunction = BLOCK_COMBINE_FUNCTION;
        outputFunction = BLOCK_OUTPUT_FUNCTION;
    }
    inputFunction = inputFunction.bindTo(compareMethodHandle);
    combineFunction = combineFunction.bindTo(compareMethodHandle);
    outputFunction = outputFunction.bindTo(type);
    AccumulatorStateFactory<?> stateFactory = StateCompiler.generateStateFactory(stateInterface, classLoader);
    Type intermediateType = stateSerializer.getSerializedType();
    AggregationMetadata metadata = new AggregationMetadata(generateAggregationName(getSignature().getName(), type.getTypeSignature(), inputTypes.stream().map(Type::getTypeSignature).collect(toImmutableList())), createParameterMetadata(type), inputFunction, combineFunction, outputFunction, stateInterface, stateSerializer, stateFactory, type);
    GenericAccumulatorFactoryBinder factory = AccumulatorCompiler.generateAccumulatorFactoryBinder(metadata, classLoader);
    return new InternalAggregationFunction(getSignature().getName(), inputTypes, intermediateType, type, true, factory);
}
Also used : DynamicClassLoader(com.facebook.presto.bytecode.DynamicClassLoader) BlockStateSerializer(com.facebook.presto.operator.aggregation.state.BlockStateSerializer) NullableBooleanState(com.facebook.presto.operator.aggregation.state.NullableBooleanState) Type(com.facebook.presto.spi.type.Type) OperatorType(com.facebook.presto.spi.function.OperatorType) BlockState(com.facebook.presto.operator.aggregation.state.BlockState) NullableDoubleState(com.facebook.presto.operator.aggregation.state.NullableDoubleState) MethodHandle(java.lang.invoke.MethodHandle)

Example 2 with BlockStateSerializer

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

the class ArbitraryAggregationFunction method generateAggregation.

private static InternalAggregationFunction generateAggregation(Type type) {
    DynamicClassLoader classLoader = new DynamicClassLoader(ArbitraryAggregationFunction.class.getClassLoader());
    List<Type> inputTypes = ImmutableList.of(type);
    MethodHandle inputFunction;
    MethodHandle combineFunction;
    MethodHandle outputFunction;
    Class<? extends AccumulatorState> stateInterface;
    AccumulatorStateSerializer<?> stateSerializer;
    if (type.getJavaType() == long.class) {
        stateInterface = NullableLongState.class;
        stateSerializer = StateCompiler.generateStateSerializer(stateInterface, classLoader);
        inputFunction = LONG_INPUT_FUNCTION;
        combineFunction = LONG_COMBINE_FUNCTION;
        outputFunction = LONG_OUTPUT_FUNCTION;
    } else if (type.getJavaType() == double.class) {
        stateInterface = NullableDoubleState.class;
        stateSerializer = StateCompiler.generateStateSerializer(stateInterface, classLoader);
        inputFunction = DOUBLE_INPUT_FUNCTION;
        combineFunction = DOUBLE_COMBINE_FUNCTION;
        outputFunction = DOUBLE_OUTPUT_FUNCTION;
    } else if (type.getJavaType() == Slice.class) {
        stateInterface = SliceState.class;
        stateSerializer = StateCompiler.generateStateSerializer(stateInterface, classLoader);
        inputFunction = SLICE_INPUT_FUNCTION;
        combineFunction = SLICE_COMBINE_FUNCTION;
        outputFunction = SLICE_OUTPUT_FUNCTION;
    } else if (type.getJavaType() == boolean.class) {
        stateInterface = NullableBooleanState.class;
        stateSerializer = StateCompiler.generateStateSerializer(stateInterface, classLoader);
        inputFunction = BOOLEAN_INPUT_FUNCTION;
        combineFunction = BOOLEAN_COMBINE_FUNCTION;
        outputFunction = BOOLEAN_OUTPUT_FUNCTION;
    } else {
        stateInterface = BlockState.class;
        stateSerializer = new BlockStateSerializer(type);
        inputFunction = BLOCK_INPUT_FUNCTION;
        combineFunction = BLOCK_COMBINE_FUNCTION;
        outputFunction = BLOCK_OUTPUT_FUNCTION;
    }
    inputFunction = inputFunction.bindTo(type);
    Type intermediateType = stateSerializer.getSerializedType();
    List<ParameterMetadata> inputParameterMetadata = createInputParameterMetadata(type);
    AggregationMetadata metadata = new AggregationMetadata(generateAggregationName(NAME, type.getTypeSignature(), inputTypes.stream().map(Type::getTypeSignature).collect(toImmutableList())), inputParameterMetadata, inputFunction, combineFunction, outputFunction.bindTo(type), stateInterface, stateSerializer, StateCompiler.generateStateFactory(stateInterface, classLoader), type);
    GenericAccumulatorFactoryBinder factory = AccumulatorCompiler.generateAccumulatorFactoryBinder(metadata, classLoader);
    return new InternalAggregationFunction(NAME, inputTypes, intermediateType, type, true, factory);
}
Also used : DynamicClassLoader(com.facebook.presto.bytecode.DynamicClassLoader) BlockStateSerializer(com.facebook.presto.operator.aggregation.state.BlockStateSerializer) NullableBooleanState(com.facebook.presto.operator.aggregation.state.NullableBooleanState) ParameterMetadata(com.facebook.presto.operator.aggregation.AggregationMetadata.ParameterMetadata) Type(com.facebook.presto.spi.type.Type) BlockState(com.facebook.presto.operator.aggregation.state.BlockState) NullableDoubleState(com.facebook.presto.operator.aggregation.state.NullableDoubleState) MethodHandle(java.lang.invoke.MethodHandle)

Aggregations

DynamicClassLoader (com.facebook.presto.bytecode.DynamicClassLoader)2 BlockState (com.facebook.presto.operator.aggregation.state.BlockState)2 BlockStateSerializer (com.facebook.presto.operator.aggregation.state.BlockStateSerializer)2 NullableBooleanState (com.facebook.presto.operator.aggregation.state.NullableBooleanState)2 NullableDoubleState (com.facebook.presto.operator.aggregation.state.NullableDoubleState)2 Type (com.facebook.presto.spi.type.Type)2 MethodHandle (java.lang.invoke.MethodHandle)2 ParameterMetadata (com.facebook.presto.operator.aggregation.AggregationMetadata.ParameterMetadata)1 OperatorType (com.facebook.presto.spi.function.OperatorType)1