@Override
protected Object visitFunctionCall(FunctionCall node, Object context)
{
List<Type> argumentTypes = new ArrayList<>();
List<Object> argumentValues = new ArrayList<>();
for (Expression expression : node.getArguments()) {
Object value = process(expression, context);
Type type = expressionTypes.get(expression);
argumentValues.add(value);
argumentTypes.add(type);
}
Signature functionSignature = metadata.getFunctionRegistry().resolveFunction(node.getName(), Lists.transform(argumentTypes, Type::getTypeSignature), false);
ScalarFunctionImplementation function = metadata.getFunctionRegistry().getScalarFunctionImplementation(functionSignature);
for (int i = 0; i < argumentValues.size(); i++) {
Object value = argumentValues.get(i);
if (value == null && !function.getNullableArguments().get(i)) {
return null;
}
}
if (optimize && (!function.isDeterministic() || hasUnresolvedValue(argumentValues))) {
return new FunctionCall(node.getName(), node.getWindow(), node.isDistinct(), toExpressions(argumentValues, argumentTypes));
}
return invoke(session, function, argumentValues);
}