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));
}
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));
}
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));
}
Aggregations