Search in sources :

Example 1 with SqlFunctionHandle

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

the class ThriftSqlFunctionExecutor method executeFunction.

@Override
public CompletableFuture<SqlFunctionResult> executeFunction(String source, RemoteScalarFunctionImplementation functionImplementation, Page input, List<Integer> channels, List<Type> argumentTypes, Type returnType) {
    ThriftUdfPage page = buildThriftPage(functionImplementation, input, channels, argumentTypes);
    SqlFunctionHandle functionHandle = functionImplementation.getFunctionHandle();
    SqlFunctionId functionId = functionHandle.getFunctionId();
    ThriftFunctionHandle thriftFunctionHandle = new ThriftFunctionHandle(functionId.getFunctionName().toString(), functionId.getArgumentTypes().stream().map(TypeSignature::toString).collect(toImmutableList()), returnType.toString(), functionHandle.getVersion());
    ThriftUdfService thriftUdfService = thriftUdfClient.get(Optional.of(functionImplementation.getLanguage().getLanguage()));
    return invokeUdfWithRetry(thriftUdfService, new ThriftUdfRequest(source, thriftFunctionHandle, page)).thenApply(thriftResult -> toSqlFunctionResult(thriftResult, returnType));
}
Also used : TypeSignature(com.facebook.presto.common.type.TypeSignature) SqlFunctionId(com.facebook.presto.spi.function.SqlFunctionId) ThriftFunctionHandle(com.facebook.presto.thrift.api.udf.ThriftFunctionHandle) ThriftUdfRequest(com.facebook.presto.thrift.api.udf.ThriftUdfRequest) SqlFunctionHandle(com.facebook.presto.spi.function.SqlFunctionHandle) ThriftUdfPage(com.facebook.presto.thrift.api.udf.ThriftUdfPage) ThriftUdfService(com.facebook.presto.thrift.api.udf.ThriftUdfService)

Example 2 with SqlFunctionHandle

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

the class TestMySqlFunctionNamespaceManager method testInvalidFunctionHandle.

@Test(expectedExceptions = UncheckedExecutionException.class, expectedExceptionsMessageRegExp = ".*Invalid FunctionHandle: unittest\\.memory\\.power_tower\\(double\\):2")
public void testInvalidFunctionHandle() {
    createFunction(FUNCTION_POWER_TOWER_DOUBLE, true);
    SqlFunctionHandle functionHandle = new SqlFunctionHandle(FUNCTION_POWER_TOWER_DOUBLE.getFunctionId(), "2");
    functionNamespaceManager.getFunctionMetadata(functionHandle);
}
Also used : SqlFunctionHandle(com.facebook.presto.spi.function.SqlFunctionHandle) Test(org.testng.annotations.Test)

Example 3 with SqlFunctionHandle

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

the class AbstractSqlInvokedFunctionNamespaceManager method executeFunction.

@Override
public CompletableFuture<SqlFunctionResult> executeFunction(String source, FunctionHandle functionHandle, Page input, List<Integer> channels, TypeManager typeManager) {
    checkArgument(functionHandle instanceof SqlFunctionHandle, format("Expect SqlFunctionHandle, got %s", functionHandle.getClass()));
    FunctionMetadata functionMetadata = getFunctionMetadata(functionHandle);
    return sqlFunctionExecutors.executeFunction(source, getScalarFunctionImplementation(functionHandle), input, channels, functionMetadata.getArgumentTypes().stream().map(typeManager::getType).collect(toImmutableList()), typeManager.getType(functionMetadata.getReturnType()));
}
Also used : FunctionMetadata(com.facebook.presto.spi.function.FunctionMetadata) SqlFunctionHandle(com.facebook.presto.spi.function.SqlFunctionHandle)

Example 4 with SqlFunctionHandle

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

the class GrpcSqlFunctionExecutor method executeFunction.

@Override
public CompletableFuture<SqlFunctionResult> executeFunction(String source, RemoteScalarFunctionImplementation functionImplementation, Page input, List<Integer> channels, List<Type> argumentTypes, Type returnType) {
    GrpcUdfPage grpcUdfPage = buildGrpcUdfPage(input, channels, grpcUdfConfigs.get(functionImplementation.getLanguage()).getGrpcUdfPageFormat());
    SqlFunctionHandle functionHandle = functionImplementation.getFunctionHandle();
    SqlFunctionId functionId = functionHandle.getFunctionId();
    GrpcFunctionHandle grpcFunctionHandle = GrpcFunctionHandle.newBuilder().setFunctionName(functionId.getFunctionName().toString()).addAllArgumentTypes(functionId.getArgumentTypes().stream().map(TypeSignature::toString).collect(toImmutableList())).setReturnType(returnType.toString()).setVersion(functionHandle.getVersion()).build();
    GrpcUdfRequest grpcUdfRequest = GrpcUdfRequest.newBuilder().setSource(source).setGrpcFunctionHandle(grpcFunctionHandle).setInputs(grpcUdfPage).build();
    return invokeUdfWithRetry(futureStubs.get(functionImplementation.getLanguage()), grpcUdfRequest).thenApply(grpcResult -> toSqlFunctionResult(grpcResult));
}
Also used : GrpcUdfRequest(com.facebook.presto.grpc.udf.GrpcUdfRequest) SqlFunctionId(com.facebook.presto.spi.function.SqlFunctionId) GrpcUtils.toGrpcUdfPage(com.facebook.presto.grpc.api.udf.GrpcUtils.toGrpcUdfPage) GrpcUdfPage(com.facebook.presto.grpc.udf.GrpcUdfPage) SqlFunctionHandle(com.facebook.presto.spi.function.SqlFunctionHandle) GrpcFunctionHandle(com.facebook.presto.grpc.udf.GrpcFunctionHandle)

Aggregations

SqlFunctionHandle (com.facebook.presto.spi.function.SqlFunctionHandle)4 SqlFunctionId (com.facebook.presto.spi.function.SqlFunctionId)2 TypeSignature (com.facebook.presto.common.type.TypeSignature)1 GrpcUtils.toGrpcUdfPage (com.facebook.presto.grpc.api.udf.GrpcUtils.toGrpcUdfPage)1 GrpcFunctionHandle (com.facebook.presto.grpc.udf.GrpcFunctionHandle)1 GrpcUdfPage (com.facebook.presto.grpc.udf.GrpcUdfPage)1 GrpcUdfRequest (com.facebook.presto.grpc.udf.GrpcUdfRequest)1 FunctionMetadata (com.facebook.presto.spi.function.FunctionMetadata)1 ThriftFunctionHandle (com.facebook.presto.thrift.api.udf.ThriftFunctionHandle)1 ThriftUdfPage (com.facebook.presto.thrift.api.udf.ThriftUdfPage)1 ThriftUdfRequest (com.facebook.presto.thrift.api.udf.ThriftUdfRequest)1 ThriftUdfService (com.facebook.presto.thrift.api.udf.ThriftUdfService)1 Test (org.testng.annotations.Test)1