Search in sources :

Example 11 with JavaScalarFunctionImplementation

use of com.facebook.presto.spi.function.JavaScalarFunctionImplementation in project presto by prestodb.

the class ArrayToArrayCast method specialize.

@Override
public BuiltInScalarFunctionImplementation specialize(BoundVariables boundVariables, int arity, FunctionAndTypeManager functionAndTypeManager) {
    checkArgument(arity == 1, "Expected arity to be 1");
    Type fromType = boundVariables.getTypeVariable("F");
    Type toType = boundVariables.getTypeVariable("T");
    FunctionHandle functionHandle = functionAndTypeManager.lookupCast(CastType.CAST, fromType.getTypeSignature(), toType.getTypeSignature());
    JavaScalarFunctionImplementation function = functionAndTypeManager.getJavaScalarFunctionImplementation(functionHandle);
    Class<?> castOperatorClass = generateArrayCast(functionAndTypeManager, functionAndTypeManager.getFunctionMetadata(functionHandle), function);
    MethodHandle methodHandle = methodHandle(castOperatorClass, "castArray", SqlFunctionProperties.class, Block.class);
    return new BuiltInScalarFunctionImplementation(false, ImmutableList.of(valueTypeArgumentProperty(RETURN_NULL_ON_NULL), valueTypeArgumentProperty(RETURN_NULL_ON_NULL)), methodHandle);
}
Also used : JavaScalarFunctionImplementation(com.facebook.presto.spi.function.JavaScalarFunctionImplementation) CastType(com.facebook.presto.metadata.CastType) Type(com.facebook.presto.common.type.Type) FunctionHandle(com.facebook.presto.spi.function.FunctionHandle) MethodHandle(java.lang.invoke.MethodHandle)

Example 12 with JavaScalarFunctionImplementation

use of com.facebook.presto.spi.function.JavaScalarFunctionImplementation in project presto by prestodb.

the class FunctionAndTypeManager method getJavaScalarFunctionImplementation.

public JavaScalarFunctionImplementation getJavaScalarFunctionImplementation(FunctionHandle functionHandle) {
    ScalarFunctionImplementation implementation = getScalarFunctionImplementation(functionHandle);
    checkArgument(implementation instanceof JavaScalarFunctionImplementation, format("Implementation of function %s is not a JavaScalarFunctionImplementation", getFunctionMetadata(functionHandle).getName()));
    return (JavaScalarFunctionImplementation) implementation;
}
Also used : ScalarFunctionImplementation(com.facebook.presto.spi.function.ScalarFunctionImplementation) JavaScalarFunctionImplementation(com.facebook.presto.spi.function.JavaScalarFunctionImplementation) JavaScalarFunctionImplementation(com.facebook.presto.spi.function.JavaScalarFunctionImplementation)

Aggregations

JavaScalarFunctionImplementation (com.facebook.presto.spi.function.JavaScalarFunctionImplementation)12 Variable (com.facebook.presto.bytecode.Variable)7 Type (com.facebook.presto.common.type.Type)7 FunctionHandle (com.facebook.presto.spi.function.FunctionHandle)7 BytecodeBlock (com.facebook.presto.bytecode.BytecodeBlock)6 IfStatement (com.facebook.presto.bytecode.control.IfStatement)6 BytecodeNode (com.facebook.presto.bytecode.BytecodeNode)5 Scope (com.facebook.presto.bytecode.Scope)5 LabelNode (com.facebook.presto.bytecode.instruction.LabelNode)4 MethodHandle (java.lang.invoke.MethodHandle)4 MethodDefinition (com.facebook.presto.bytecode.MethodDefinition)3 Parameter (com.facebook.presto.bytecode.Parameter)3 BytecodeExpression (com.facebook.presto.bytecode.expression.BytecodeExpression)3 CastType (com.facebook.presto.metadata.CastType)3 RowExpression (com.facebook.presto.spi.relation.RowExpression)3 SqlTypeBytecodeExpression.constantType (com.facebook.presto.sql.gen.SqlTypeBytecodeExpression.constantType)3 CallSiteBinder (com.facebook.presto.bytecode.CallSiteBinder)2 ClassDefinition (com.facebook.presto.bytecode.ClassDefinition)2 BigintType (com.facebook.presto.common.type.BigintType)2 FunctionAndTypeManager (com.facebook.presto.metadata.FunctionAndTypeManager)2