use of com.facebook.presto.spi.function.RoutineCharacteristics.Determinism.DETERMINISTIC in project presto by prestodb.
the class SqlInvokedScalarFromAnnotationsParser method createSqlInvokedFunctions.
private static List<SqlInvokedFunction> createSqlInvokedFunctions(Method method, Optional<SqlInvokedScalarFunction> header, Optional<String> description) {
SqlInvokedScalarFunction functionHeader = header.orElse(method.getAnnotation(SqlInvokedScalarFunction.class));
String functionDescription = description.orElse(method.isAnnotationPresent(Description.class) ? method.getAnnotation(Description.class).value() : "");
TypeSignature returnType = parseTypeSignature(method.getAnnotation(SqlType.class).value());
// Parameter
checkCondition(!method.isAnnotationPresent(SqlParameter.class) || !method.isAnnotationPresent(SqlParameters.class), FUNCTION_IMPLEMENTATION_ERROR, "Function-defining method [%s] is annotated with both @SqlParameter and @SqlParameters", method);
List<Parameter> parameters;
if (method.isAnnotationPresent(SqlParameter.class)) {
parameters = ImmutableList.of(getParameterFromAnnotation(method.getAnnotation(SqlParameter.class)));
} else if (method.isAnnotationPresent(SqlParameters.class)) {
parameters = stream(method.getAnnotation(SqlParameters.class).value()).map(SqlInvokedScalarFromAnnotationsParser::getParameterFromAnnotation).collect(toImmutableList());
} else {
parameters = ImmutableList.of();
}
// Routine characteristics
RoutineCharacteristics routineCharacteristics = RoutineCharacteristics.builder().setLanguage(RoutineCharacteristics.Language.SQL).setDeterminism(functionHeader.deterministic() ? DETERMINISTIC : NOT_DETERMINISTIC).setNullCallClause(functionHeader.calledOnNullInput() ? CALLED_ON_NULL_INPUT : RETURNS_NULL_ON_NULL_INPUT).build();
String body;
try {
body = (String) method.invoke(null);
} catch (ReflectiveOperationException e) {
throw new PrestoException(FUNCTION_IMPLEMENTATION_ERROR, format("Failed to get function body for method [%s]", method), e);
}
return Stream.concat(Stream.of(functionHeader.value()), stream(functionHeader.alias())).map(name -> new SqlInvokedFunction(QualifiedObjectName.valueOf(DEFAULT_NAMESPACE, name), parameters, returnType, functionDescription, routineCharacteristics, body, notVersioned())).collect(toImmutableList());
}
Aggregations