use of io.confluent.ksql.execution.util.FunctionArgumentsUtil.ArgumentInfo in project ksql by confluentinc.
the class TermCompiler method visitFunctionCall.
@Override
public Term visitFunctionCall(final FunctionCall node, final Context context) {
final UdfFactory udfFactory = functionRegistry.getUdfFactory(node.getName());
final FunctionTypeInfo argumentsAndContext = FunctionArgumentsUtil.getFunctionTypeInfo(expressionTypeManager, node, udfFactory, context.getLambdaSqlTypeMapping());
final List<ArgumentInfo> argumentInfos = argumentsAndContext.getArgumentInfos();
final KsqlScalarFunction function = argumentsAndContext.getFunction();
final SqlType functionReturnSchema = argumentsAndContext.getReturnType();
final Class<?> javaClass = SchemaConverters.sqlToJavaConverter().toJavaType(functionReturnSchema);
final List<Expression> arguments = node.getArguments();
final List<Term> args = new ArrayList<>();
for (int i = 0; i < arguments.size(); i++) {
final Expression arg = arguments.get(i);
// lambda arguments and null values are considered to have null type
final SqlType sqlType = argumentInfos.get(i).getSqlArgument().getSqlType().orElse(null);
;
final ParamType paramType;
if (i >= function.parameters().size() - 1 && function.isVariadic()) {
paramType = ((ArrayType) Iterables.getLast(function.parameters())).element();
} else {
paramType = function.parameters().get(i);
}
// This will attempt to cast to the expected argument type and will throw an error if
// it cannot be done.
final Term argTerm = process(convertArgument(arg, sqlType, paramType), new Context(argumentInfos.get(i).getLambdaSqlTypeMapping()));
args.add(argTerm);
}
final Kudf kudf = function.newInstance(ksqlConfig);
return new FunctionCallTerm(kudf, args, javaClass, functionReturnSchema);
}
Aggregations