use of io.trino.metadata.FunctionDependencies in project trino by trinodb.
the class ParametricAggregation method specialize.
@Override
public AggregationMetadata specialize(BoundSignature boundSignature, FunctionDependencies functionDependencies) {
// Find implementation matching arguments
AggregationImplementation concreteImplementation = findMatchingImplementation(boundSignature);
// Build state factory and serializer
AccumulatorStateDescriptor<?> accumulatorStateDescriptor = generateAccumulatorStateDescriptor(stateClass);
// Bind provided dependencies to aggregation method handlers
FunctionMetadata metadata = getFunctionMetadata();
FunctionBinding functionBinding = SignatureBinder.bindFunction(metadata.getFunctionId(), metadata.getSignature(), boundSignature);
MethodHandle inputHandle = bindDependencies(concreteImplementation.getInputFunction(), concreteImplementation.getInputDependencies(), functionBinding, functionDependencies);
Optional<MethodHandle> removeInputHandle = concreteImplementation.getRemoveInputFunction().map(removeInputFunction -> bindDependencies(removeInputFunction, concreteImplementation.getRemoveInputDependencies(), functionBinding, functionDependencies));
Optional<MethodHandle> combineHandle = concreteImplementation.getCombineFunction();
if (getAggregationMetadata().isDecomposable()) {
checkArgument(combineHandle.isPresent(), "Decomposable method %s does not have a combine method", boundSignature.getName());
combineHandle = combineHandle.map(combineFunction -> bindDependencies(combineFunction, concreteImplementation.getCombineDependencies(), functionBinding, functionDependencies));
} else {
checkArgument(concreteImplementation.getCombineFunction().isEmpty(), "Decomposable method %s does not have a combine method", boundSignature.getName());
}
MethodHandle outputHandle = bindDependencies(concreteImplementation.getOutputFunction(), concreteImplementation.getOutputDependencies(), functionBinding, functionDependencies);
List<AggregationParameterKind> inputParameterKinds = concreteImplementation.getInputParameterKinds();
inputHandle = normalizeInputMethod(inputHandle, boundSignature, inputParameterKinds);
removeInputHandle = removeInputHandle.map(function -> normalizeInputMethod(function, boundSignature, inputParameterKinds));
return new AggregationMetadata(inputHandle, removeInputHandle, combineHandle, outputHandle, ImmutableList.of(accumulatorStateDescriptor));
}
use of io.trino.metadata.FunctionDependencies in project trino by trinodb.
the class TestAnnotationEngineForAggregates method specializeAggregationFunction.
private static void specializeAggregationFunction(BoundSignature boundSignature, SqlAggregationFunction aggregation) {
FunctionMetadata functionMetadata = aggregation.getFunctionMetadata();
FunctionBinding functionBinding = MetadataManager.toFunctionBinding(functionMetadata.getFunctionId(), boundSignature, functionMetadata.getSignature());
AggregationFunctionMetadata aggregationMetadata = aggregation.getAggregationMetadata();
assertFalse(aggregationMetadata.isOrderSensitive());
assertFalse(aggregationMetadata.getIntermediateTypes().isEmpty());
ResolvedFunction resolvedFunction = METADATA.resolve(TEST_SESSION, functionBinding, functionMetadata, aggregation.getFunctionDependencies(boundSignature));
FunctionDependencies functionDependencies = new FunctionDependencies(FUNCTION_MANAGER::getScalarFunctionInvoker, resolvedFunction.getTypeDependencies(), resolvedFunction.getFunctionDependencies());
aggregation.specialize(boundSignature, functionDependencies);
}
use of io.trino.metadata.FunctionDependencies in project trino by trinodb.
the class TestAnnotationEngineForScalars method testSingleImplementationScalarParse.
@Test
public void testSingleImplementationScalarParse() {
Signature expectedSignature = new Signature("single_implementation_parametric_scalar", DOUBLE.getTypeSignature(), ImmutableList.of(DOUBLE.getTypeSignature()));
List<SqlScalarFunction> functions = ScalarFromAnnotationsParser.parseFunctionDefinition(SingleImplementationScalarFunction.class);
assertEquals(functions.size(), 1);
ParametricScalar scalar = (ParametricScalar) functions.get(0);
FunctionMetadata functionMetadata = scalar.getFunctionMetadata();
assertEquals(functionMetadata.getSignature(), expectedSignature);
assertTrue(functionMetadata.isDeterministic());
assertFalse(functionMetadata.isHidden());
assertEquals(functionMetadata.getDescription(), "Simple scalar with single implementation based on class");
assertFalse(functionMetadata.getFunctionNullability().isArgumentNullable(0));
assertImplementationCount(scalar, 1, 0, 0);
BoundSignature boundSignature = new BoundSignature(expectedSignature.getName(), DOUBLE, ImmutableList.of(DOUBLE));
ChoicesScalarFunctionImplementation specialized = (ChoicesScalarFunctionImplementation) scalar.specialize(boundSignature, new FunctionDependencies(FUNCTION_MANAGER::getScalarFunctionInvoker, ImmutableMap.of(), ImmutableSet.of()));
assertFalse(specialized.getChoices().get(0).getInstanceFactory().isPresent());
}
Aggregations