use of com.facebook.presto.operator.scalar.annotations.ParametricScalarImplementation in project presto by prestodb.
the class ParametricScalar method specialize.
@Override
public BuiltInScalarFunctionImplementation specialize(BoundVariables boundVariables, int arity, FunctionAndTypeManager functionAndTypeManager) {
Signature boundSignature = applyBoundVariables(getSignature(), boundVariables, arity);
if (implementations.getExactImplementations().containsKey(boundSignature)) {
ParametricScalarImplementation implementation = implementations.getExactImplementations().get(boundSignature);
Optional<BuiltInScalarFunctionImplementation> scalarFunctionImplementation = implementation.specialize(boundSignature, boundVariables, functionAndTypeManager);
checkCondition(scalarFunctionImplementation.isPresent(), FUNCTION_IMPLEMENTATION_ERROR, String.format("Exact implementation of %s do not match expected java types.", boundSignature.getNameSuffix()));
return scalarFunctionImplementation.get();
}
BuiltInScalarFunctionImplementation selectedImplementation = null;
for (ParametricScalarImplementation implementation : implementations.getSpecializedImplementations()) {
Optional<BuiltInScalarFunctionImplementation> scalarFunctionImplementation = implementation.specialize(boundSignature, boundVariables, functionAndTypeManager);
if (scalarFunctionImplementation.isPresent()) {
checkCondition(selectedImplementation == null, AMBIGUOUS_FUNCTION_IMPLEMENTATION, "Ambiguous implementation for %s with bindings %s", getSignature(), boundVariables.getTypeVariables());
selectedImplementation = scalarFunctionImplementation.get();
}
}
if (selectedImplementation != null) {
return selectedImplementation;
}
for (ParametricScalarImplementation implementation : implementations.getGenericImplementations()) {
Optional<BuiltInScalarFunctionImplementation> scalarFunctionImplementation = implementation.specialize(boundSignature, boundVariables, functionAndTypeManager);
if (scalarFunctionImplementation.isPresent()) {
checkCondition(selectedImplementation == null, AMBIGUOUS_FUNCTION_IMPLEMENTATION, "Ambiguous implementation for %s with bindings %s", getSignature(), boundVariables.getTypeVariables());
selectedImplementation = scalarFunctionImplementation.get();
}
}
if (selectedImplementation != null) {
return selectedImplementation;
}
throw new PrestoException(FUNCTION_IMPLEMENTATION_MISSING, format("Unsupported type parameters (%s) for %s", boundVariables, getSignature()));
}
Aggregations