Search in sources :

Example 1 with OutputBlockVariableAndType

use of com.facebook.presto.sql.gen.BytecodeUtils.OutputBlockVariableAndType in project presto by prestodb.

the class FunctionCallCodeGenerator method generateCall.

public BytecodeNode generateCall(FunctionHandle functionHandle, BytecodeGeneratorContext context, Type returnType, List<RowExpression> arguments, Optional<Variable> outputBlockVariable) {
    FunctionAndTypeManager functionAndTypeManager = context.getFunctionManager();
    ScalarFunctionImplementation function = functionAndTypeManager.getScalarFunctionImplementation(functionHandle);
    checkArgument(function instanceof JavaScalarFunctionImplementation, format("FunctionCallCodeGenerator only handles JavaScalarFunctionImplementation, get %s", function.getClass().getName()));
    JavaScalarFunctionImplementation javaFunction = (JavaScalarFunctionImplementation) function;
    List<BytecodeNode> argumentsBytecode = new ArrayList<>();
    ScalarFunctionImplementationChoice choice = getAllScalarFunctionImplementationChoices(javaFunction).get(0);
    for (int i = 0; i < arguments.size(); i++) {
        RowExpression argument = arguments.get(i);
        ArgumentProperty argumentProperty = choice.getArgumentProperty(i);
        if (argumentProperty.getArgumentType() == VALUE_TYPE) {
            argumentsBytecode.add(context.generate(argument, Optional.empty()));
        } else {
            argumentsBytecode.add(context.generate(argument, Optional.empty(), Optional.of(argumentProperty.getLambdaInterface())));
        }
    }
    return context.generateCall(functionAndTypeManager.getFunctionMetadata(functionHandle).getName().getObjectName(), javaFunction, argumentsBytecode, outputBlockVariable.map(variable -> new OutputBlockVariableAndType(variable, returnType)));
}
Also used : JavaScalarFunctionImplementation(com.facebook.presto.spi.function.JavaScalarFunctionImplementation) ScalarFunctionImplementation(com.facebook.presto.spi.function.ScalarFunctionImplementation) FunctionAndTypeManager(com.facebook.presto.metadata.FunctionAndTypeManager) RowExpression(com.facebook.presto.spi.relation.RowExpression) VALUE_TYPE(com.facebook.presto.operator.scalar.ScalarFunctionImplementationChoice.ArgumentType.VALUE_TYPE) Variable(com.facebook.presto.bytecode.Variable) JavaScalarFunctionImplementation(com.facebook.presto.spi.function.JavaScalarFunctionImplementation) OutputBlockVariableAndType(com.facebook.presto.sql.gen.BytecodeUtils.OutputBlockVariableAndType) ScalarFunctionImplementationChoice(com.facebook.presto.operator.scalar.ScalarFunctionImplementationChoice) String.format(java.lang.String.format) ArrayList(java.util.ArrayList) ArgumentProperty(com.facebook.presto.operator.scalar.ScalarFunctionImplementationChoice.ArgumentProperty) BytecodeUtils.getAllScalarFunctionImplementationChoices(com.facebook.presto.sql.gen.BytecodeUtils.getAllScalarFunctionImplementationChoices) BytecodeNode(com.facebook.presto.bytecode.BytecodeNode) List(java.util.List) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) ScalarFunctionImplementation(com.facebook.presto.spi.function.ScalarFunctionImplementation) FunctionHandle(com.facebook.presto.spi.function.FunctionHandle) Optional(java.util.Optional) Type(com.facebook.presto.common.type.Type) JavaScalarFunctionImplementation(com.facebook.presto.spi.function.JavaScalarFunctionImplementation) ArgumentProperty(com.facebook.presto.operator.scalar.ScalarFunctionImplementationChoice.ArgumentProperty) ScalarFunctionImplementationChoice(com.facebook.presto.operator.scalar.ScalarFunctionImplementationChoice) FunctionAndTypeManager(com.facebook.presto.metadata.FunctionAndTypeManager) ArrayList(java.util.ArrayList) RowExpression(com.facebook.presto.spi.relation.RowExpression) OutputBlockVariableAndType(com.facebook.presto.sql.gen.BytecodeUtils.OutputBlockVariableAndType) BytecodeNode(com.facebook.presto.bytecode.BytecodeNode)

Aggregations

BytecodeNode (com.facebook.presto.bytecode.BytecodeNode)1 Variable (com.facebook.presto.bytecode.Variable)1 Type (com.facebook.presto.common.type.Type)1 FunctionAndTypeManager (com.facebook.presto.metadata.FunctionAndTypeManager)1 ScalarFunctionImplementationChoice (com.facebook.presto.operator.scalar.ScalarFunctionImplementationChoice)1 ArgumentProperty (com.facebook.presto.operator.scalar.ScalarFunctionImplementationChoice.ArgumentProperty)1 VALUE_TYPE (com.facebook.presto.operator.scalar.ScalarFunctionImplementationChoice.ArgumentType.VALUE_TYPE)1 FunctionHandle (com.facebook.presto.spi.function.FunctionHandle)1 JavaScalarFunctionImplementation (com.facebook.presto.spi.function.JavaScalarFunctionImplementation)1 ScalarFunctionImplementation (com.facebook.presto.spi.function.ScalarFunctionImplementation)1 RowExpression (com.facebook.presto.spi.relation.RowExpression)1 OutputBlockVariableAndType (com.facebook.presto.sql.gen.BytecodeUtils.OutputBlockVariableAndType)1 BytecodeUtils.getAllScalarFunctionImplementationChoices (com.facebook.presto.sql.gen.BytecodeUtils.getAllScalarFunctionImplementationChoices)1 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 String.format (java.lang.String.format)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Optional (java.util.Optional)1