Search in sources :

Example 1 with GenericDoubleStateSerializer

use of io.trino.operator.aggregation.state.GenericDoubleStateSerializer in project trino by trinodb.

the class ArbitraryAggregationFunction method specialize.

@Override
public AggregationMetadata specialize(BoundSignature boundSignature) {
    Type type = boundSignature.getReturnType();
    MethodHandle inputFunction;
    MethodHandle combineFunction;
    MethodHandle outputFunction;
    AccumulatorStateDescriptor<?> accumulatorStateDescriptor;
    if (type.getJavaType() == long.class) {
        accumulatorStateDescriptor = new AccumulatorStateDescriptor<>(GenericLongState.class, new GenericLongStateSerializer(type), StateCompiler.generateStateFactory(GenericLongState.class));
        inputFunction = LONG_INPUT_FUNCTION;
        combineFunction = LONG_COMBINE_FUNCTION;
        outputFunction = LONG_OUTPUT_FUNCTION;
    } else if (type.getJavaType() == double.class) {
        accumulatorStateDescriptor = new AccumulatorStateDescriptor<>(GenericDoubleState.class, new GenericDoubleStateSerializer(type), StateCompiler.generateStateFactory(GenericDoubleState.class));
        inputFunction = DOUBLE_INPUT_FUNCTION;
        combineFunction = DOUBLE_COMBINE_FUNCTION;
        outputFunction = DOUBLE_OUTPUT_FUNCTION;
    } else if (type.getJavaType() == boolean.class) {
        accumulatorStateDescriptor = new AccumulatorStateDescriptor<>(GenericBooleanState.class, new GenericBooleanStateSerializer(type), StateCompiler.generateStateFactory(GenericBooleanState.class));
        inputFunction = BOOLEAN_INPUT_FUNCTION;
        combineFunction = BOOLEAN_COMBINE_FUNCTION;
        outputFunction = BOOLEAN_OUTPUT_FUNCTION;
    } else {
        // native container type is Slice or Block
        accumulatorStateDescriptor = new AccumulatorStateDescriptor<>(BlockPositionState.class, new BlockPositionStateSerializer(type), StateCompiler.generateStateFactory(BlockPositionState.class));
        inputFunction = BLOCK_POSITION_INPUT_FUNCTION;
        combineFunction = BLOCK_POSITION_COMBINE_FUNCTION;
        outputFunction = BLOCK_POSITION_OUTPUT_FUNCTION;
    }
    inputFunction = inputFunction.bindTo(type);
    return new AggregationMetadata(inputFunction, Optional.empty(), Optional.of(combineFunction), outputFunction.bindTo(type), ImmutableList.of(accumulatorStateDescriptor));
}
Also used : GenericLongState(io.trino.operator.aggregation.state.GenericLongState) AccumulatorStateDescriptor(io.trino.operator.aggregation.AggregationMetadata.AccumulatorStateDescriptor) GenericDoubleState(io.trino.operator.aggregation.state.GenericDoubleState) BlockPositionStateSerializer(io.trino.operator.aggregation.state.BlockPositionStateSerializer) GenericBooleanState(io.trino.operator.aggregation.state.GenericBooleanState) BlockPositionState(io.trino.operator.aggregation.state.BlockPositionState) Type(io.trino.spi.type.Type) GenericLongStateSerializer(io.trino.operator.aggregation.state.GenericLongStateSerializer) GenericDoubleStateSerializer(io.trino.operator.aggregation.state.GenericDoubleStateSerializer) GenericBooleanStateSerializer(io.trino.operator.aggregation.state.GenericBooleanStateSerializer) MethodHandle(java.lang.invoke.MethodHandle)

Example 2 with GenericDoubleStateSerializer

use of io.trino.operator.aggregation.state.GenericDoubleStateSerializer in project trino by trinodb.

the class AbstractMinMaxAggregationFunction method specialize.

@Override
public AggregationMetadata specialize(BoundSignature boundSignature, FunctionDependencies functionDependencies) {
    Type type = boundSignature.getArgumentTypes().get(0);
    InvocationConvention invocationConvention;
    if (type.getJavaType().isPrimitive()) {
        invocationConvention = simpleConvention(FAIL_ON_NULL, NEVER_NULL, NEVER_NULL);
    } else {
        invocationConvention = simpleConvention(FAIL_ON_NULL, BLOCK_POSITION, BLOCK_POSITION);
    }
    MethodHandle compareMethodHandle = getMinMaxCompare(functionDependencies, type, invocationConvention, min);
    MethodHandle inputFunction;
    MethodHandle combineFunction;
    MethodHandle outputFunction;
    AccumulatorStateDescriptor<?> accumulatorStateDescriptor;
    if (type.getJavaType() == long.class) {
        accumulatorStateDescriptor = new AccumulatorStateDescriptor<>(GenericLongState.class, new GenericLongStateSerializer(type), StateCompiler.generateStateFactory(GenericLongState.class));
        inputFunction = LONG_INPUT_FUNCTION.bindTo(compareMethodHandle);
        combineFunction = LONG_COMBINE_FUNCTION.bindTo(compareMethodHandle);
        outputFunction = LONG_OUTPUT_FUNCTION.bindTo(type);
    } else if (type.getJavaType() == double.class) {
        accumulatorStateDescriptor = new AccumulatorStateDescriptor<>(GenericDoubleState.class, new GenericDoubleStateSerializer(type), StateCompiler.generateStateFactory(GenericDoubleState.class));
        inputFunction = DOUBLE_INPUT_FUNCTION.bindTo(compareMethodHandle);
        combineFunction = DOUBLE_COMBINE_FUNCTION.bindTo(compareMethodHandle);
        outputFunction = DOUBLE_OUTPUT_FUNCTION.bindTo(type);
    } else if (type.getJavaType() == boolean.class) {
        accumulatorStateDescriptor = new AccumulatorStateDescriptor<>(GenericBooleanState.class, new GenericBooleanStateSerializer(type), StateCompiler.generateStateFactory(GenericBooleanState.class));
        inputFunction = BOOLEAN_INPUT_FUNCTION.bindTo(compareMethodHandle);
        combineFunction = BOOLEAN_COMBINE_FUNCTION.bindTo(compareMethodHandle);
        outputFunction = BOOLEAN_OUTPUT_FUNCTION.bindTo(type);
    } else {
        // native container type is Object
        accumulatorStateDescriptor = new AccumulatorStateDescriptor<>(BlockPositionState.class, new BlockPositionStateSerializer(type), StateCompiler.generateStateFactory(BlockPositionState.class));
        inputFunction = BLOCK_POSITION_INPUT_FUNCTION.bindTo(compareMethodHandle);
        combineFunction = BLOCK_POSITION_COMBINE_FUNCTION.bindTo(compareMethodHandle);
        outputFunction = BLOCK_POSITION_OUTPUT_FUNCTION.bindTo(type);
    }
    inputFunction = normalizeInputMethod(inputFunction, boundSignature, createInputParameterKinds(type));
    return new AggregationMetadata(inputFunction, Optional.empty(), Optional.of(combineFunction), outputFunction, ImmutableList.of(accumulatorStateDescriptor));
}
Also used : GenericLongState(io.trino.operator.aggregation.state.GenericLongState) AccumulatorStateDescriptor(io.trino.operator.aggregation.AggregationMetadata.AccumulatorStateDescriptor) GenericDoubleState(io.trino.operator.aggregation.state.GenericDoubleState) BlockPositionStateSerializer(io.trino.operator.aggregation.state.BlockPositionStateSerializer) GenericBooleanState(io.trino.operator.aggregation.state.GenericBooleanState) BlockPositionState(io.trino.operator.aggregation.state.BlockPositionState) Type(io.trino.spi.type.Type) GenericLongStateSerializer(io.trino.operator.aggregation.state.GenericLongStateSerializer) GenericDoubleStateSerializer(io.trino.operator.aggregation.state.GenericDoubleStateSerializer) InvocationConvention(io.trino.spi.function.InvocationConvention) GenericBooleanStateSerializer(io.trino.operator.aggregation.state.GenericBooleanStateSerializer) MethodHandle(java.lang.invoke.MethodHandle)

Example 3 with GenericDoubleStateSerializer

use of io.trino.operator.aggregation.state.GenericDoubleStateSerializer in project trino by trinodb.

the class ReduceAggregationFunction method specialize.

@Override
public AggregationMetadata specialize(BoundSignature boundSignature) {
    Type inputType = boundSignature.getArgumentTypes().get(0);
    Type stateType = boundSignature.getArgumentTypes().get(1);
    MethodHandle inputMethodHandle;
    MethodHandle combineMethodHandle;
    MethodHandle outputMethodHandle;
    AccumulatorStateDescriptor<?> stateDescriptor;
    if (stateType.getJavaType() == long.class) {
        inputMethodHandle = LONG_STATE_INPUT_FUNCTION;
        combineMethodHandle = LONG_STATE_COMBINE_FUNCTION;
        outputMethodHandle = LONG_STATE_OUTPUT_FUNCTION.bindTo(stateType);
        stateDescriptor = new AccumulatorStateDescriptor<>(GenericLongState.class, new GenericLongStateSerializer(stateType), StateCompiler.generateStateFactory(GenericLongState.class));
    } else if (stateType.getJavaType() == double.class) {
        inputMethodHandle = DOUBLE_STATE_INPUT_FUNCTION;
        combineMethodHandle = DOUBLE_STATE_COMBINE_FUNCTION;
        outputMethodHandle = DOUBLE_STATE_OUTPUT_FUNCTION.bindTo(stateType);
        stateDescriptor = new AccumulatorStateDescriptor<>(GenericDoubleState.class, new GenericDoubleStateSerializer(stateType), StateCompiler.generateStateFactory(GenericDoubleState.class));
    } else if (stateType.getJavaType() == boolean.class) {
        inputMethodHandle = BOOLEAN_STATE_INPUT_FUNCTION;
        combineMethodHandle = BOOLEAN_STATE_COMBINE_FUNCTION;
        outputMethodHandle = BOOLEAN_STATE_OUTPUT_FUNCTION.bindTo(stateType);
        stateDescriptor = new AccumulatorStateDescriptor<>(GenericBooleanState.class, new GenericBooleanStateSerializer(stateType), StateCompiler.generateStateFactory(GenericBooleanState.class));
    } else {
        // See JDK-8017163.
        throw new TrinoException(NOT_SUPPORTED, format("State type not supported for %s: %s", NAME, stateType.getDisplayName()));
    }
    inputMethodHandle = inputMethodHandle.asType(inputMethodHandle.type().changeParameterType(1, inputType.getJavaType()));
    inputMethodHandle = normalizeInputMethod(inputMethodHandle, boundSignature, ImmutableList.of(STATE, INPUT_CHANNEL, INPUT_CHANNEL), 2);
    return new AggregationMetadata(inputMethodHandle, Optional.empty(), Optional.of(combineMethodHandle), outputMethodHandle, ImmutableList.of(stateDescriptor), ImmutableList.of(BinaryFunctionInterface.class, BinaryFunctionInterface.class));
}
Also used : GenericLongState(io.trino.operator.aggregation.state.GenericLongState) AccumulatorStateDescriptor(io.trino.operator.aggregation.AggregationMetadata.AccumulatorStateDescriptor) BinaryFunctionInterface(io.trino.sql.gen.lambda.BinaryFunctionInterface) GenericDoubleState(io.trino.operator.aggregation.state.GenericDoubleState) GenericBooleanState(io.trino.operator.aggregation.state.GenericBooleanState) Type(io.trino.spi.type.Type) TypeSignature.functionType(io.trino.spi.type.TypeSignature.functionType) GenericLongStateSerializer(io.trino.operator.aggregation.state.GenericLongStateSerializer) GenericDoubleStateSerializer(io.trino.operator.aggregation.state.GenericDoubleStateSerializer) TrinoException(io.trino.spi.TrinoException) GenericBooleanStateSerializer(io.trino.operator.aggregation.state.GenericBooleanStateSerializer) MethodHandle(java.lang.invoke.MethodHandle)

Aggregations

AccumulatorStateDescriptor (io.trino.operator.aggregation.AggregationMetadata.AccumulatorStateDescriptor)3 GenericBooleanState (io.trino.operator.aggregation.state.GenericBooleanState)3 GenericBooleanStateSerializer (io.trino.operator.aggregation.state.GenericBooleanStateSerializer)3 GenericDoubleState (io.trino.operator.aggregation.state.GenericDoubleState)3 GenericDoubleStateSerializer (io.trino.operator.aggregation.state.GenericDoubleStateSerializer)3 GenericLongState (io.trino.operator.aggregation.state.GenericLongState)3 GenericLongStateSerializer (io.trino.operator.aggregation.state.GenericLongStateSerializer)3 Type (io.trino.spi.type.Type)3 MethodHandle (java.lang.invoke.MethodHandle)3 BlockPositionState (io.trino.operator.aggregation.state.BlockPositionState)2 BlockPositionStateSerializer (io.trino.operator.aggregation.state.BlockPositionStateSerializer)2 TrinoException (io.trino.spi.TrinoException)1 InvocationConvention (io.trino.spi.function.InvocationConvention)1 TypeSignature.functionType (io.trino.spi.type.TypeSignature.functionType)1 BinaryFunctionInterface (io.trino.sql.gen.lambda.BinaryFunctionInterface)1