Search in sources :

Example 1 with GrpcUdfPage

use of com.facebook.presto.grpc.udf.GrpcUdfPage in project presto by prestodb.

the class GrpcSqlFunctionExecutor method toSqlFunctionResult.

private SqlFunctionResult toSqlFunctionResult(GrpcUdfResult grpcUdfResult) {
    checkState(blockEncodingSerde != null, "blockEncodingSerde not set");
    GrpcUdfPage grpcUdfPage = grpcUdfResult.getResult();
    switch(grpcUdfPage.getGrpcUdfPageFormat()) {
        case Presto:
            Page resultPage = toPrestoPage(blockEncodingSerde, grpcUdfPage.getGrpcSerializedPage());
            return new SqlFunctionResult(resultPage.getBlock(0), grpcUdfResult.getUdfStats().getTotalCpuTimeMs());
        default:
            throw new IllegalArgumentException(format("Unknown page format: %s", grpcUdfPage.getGrpcUdfPageFormat()));
    }
}
Also used : GrpcUtils.toGrpcUdfPage(com.facebook.presto.grpc.api.udf.GrpcUtils.toGrpcUdfPage) GrpcUdfPage(com.facebook.presto.grpc.udf.GrpcUdfPage) Page(com.facebook.presto.common.Page) GrpcUtils.toPrestoPage(com.facebook.presto.grpc.api.udf.GrpcUtils.toPrestoPage) GrpcSerializedPage(com.facebook.presto.grpc.udf.GrpcSerializedPage) GrpcUtils.toGrpcUdfPage(com.facebook.presto.grpc.api.udf.GrpcUtils.toGrpcUdfPage) GrpcUtils.toGrpcSerializedPage(com.facebook.presto.grpc.api.udf.GrpcUtils.toGrpcSerializedPage) GrpcUdfPage(com.facebook.presto.grpc.udf.GrpcUdfPage) SqlFunctionResult(com.facebook.presto.common.function.SqlFunctionResult)

Example 2 with GrpcUdfPage

use of com.facebook.presto.grpc.udf.GrpcUdfPage in project presto by prestodb.

the class GrpcSqlFunctionExecutor method buildGrpcUdfPage.

private GrpcUdfPage buildGrpcUdfPage(Page input, List<Integer> channels, GrpcUdfPageFormat grpcUdfPageFormat) {
    Block[] blocks = new Block[channels.size()];
    for (int i = 0; i < channels.size(); i++) {
        blocks[i] = input.getBlock(channels.get(i));
    }
    switch(grpcUdfPageFormat) {
        case Presto:
            checkState(blockEncodingSerde != null, "blockEncodingSerde not set");
            Page inputPage = wrapBlocksWithoutCopy(input.getPositionCount(), blocks);
            GrpcSerializedPage grpcSerializedPage = toGrpcSerializedPage(blockEncodingSerde, inputPage);
            return toGrpcUdfPage(grpcUdfPageFormat, grpcSerializedPage);
        default:
            throw new IllegalArgumentException(format("Unknown page format: %s", grpcUdfPageFormat));
    }
}
Also used : Block(com.facebook.presto.common.block.Block) Page(com.facebook.presto.common.Page) GrpcUtils.toPrestoPage(com.facebook.presto.grpc.api.udf.GrpcUtils.toPrestoPage) GrpcSerializedPage(com.facebook.presto.grpc.udf.GrpcSerializedPage) GrpcUtils.toGrpcUdfPage(com.facebook.presto.grpc.api.udf.GrpcUtils.toGrpcUdfPage) GrpcUtils.toGrpcSerializedPage(com.facebook.presto.grpc.api.udf.GrpcUtils.toGrpcSerializedPage) GrpcUdfPage(com.facebook.presto.grpc.udf.GrpcUdfPage) GrpcSerializedPage(com.facebook.presto.grpc.udf.GrpcSerializedPage) GrpcUtils.toGrpcSerializedPage(com.facebook.presto.grpc.api.udf.GrpcUtils.toGrpcSerializedPage)

Example 3 with GrpcUdfPage

use of com.facebook.presto.grpc.udf.GrpcUdfPage in project presto by prestodb.

the class EchoFirstInputGrpcUdfService method invokeUdf.

@Override
public void invokeUdf(GrpcUdfRequest request, StreamObserver<GrpcUdfResult> responseObserver) {
    GrpcUdfPage grpcUdfPage = request.getInputs();
    GrpcUdfPage result;
    switch(grpcUdfPage.getGrpcUdfPageFormat()) {
        case Presto:
            Page prestoPage = toPrestoPage(blockEncodingSerde, grpcUdfPage.getGrpcSerializedPage());
            if (prestoPage.getPositionCount() == 0) {
                new UnsupportedOperationException("No input to echo");
            }
            GrpcSerializedPage grpcSerializedPage = toGrpcSerializedPage(blockEncodingSerde, new Page(prestoPage.getBlock(0)));
            result = toGrpcUdfPage(Presto, grpcSerializedPage);
            break;
        default:
            throw new UnsupportedOperationException();
    }
    GrpcUdfResult grpcUdfResult = GrpcUdfResult.newBuilder().setResult(result).setUdfStats(GrpcUdfStats.newBuilder().setTotalCpuTimeMs(100).build()).build();
    responseObserver.onNext(grpcUdfResult);
    responseObserver.onCompleted();
}
Also used : GrpcUdfResult(com.facebook.presto.grpc.udf.GrpcUdfResult) GrpcUtils.toGrpcUdfPage(com.facebook.presto.grpc.api.udf.GrpcUtils.toGrpcUdfPage) GrpcUdfPage(com.facebook.presto.grpc.udf.GrpcUdfPage) Page(com.facebook.presto.common.Page) GrpcSerializedPage(com.facebook.presto.grpc.udf.GrpcSerializedPage) GrpcUtils.toPrestoPage(com.facebook.presto.grpc.api.udf.GrpcUtils.toPrestoPage) GrpcUtils.toGrpcUdfPage(com.facebook.presto.grpc.api.udf.GrpcUtils.toGrpcUdfPage) GrpcUtils.toGrpcSerializedPage(com.facebook.presto.grpc.api.udf.GrpcUtils.toGrpcSerializedPage) GrpcUdfPage(com.facebook.presto.grpc.udf.GrpcUdfPage) GrpcSerializedPage(com.facebook.presto.grpc.udf.GrpcSerializedPage) GrpcUtils.toGrpcSerializedPage(com.facebook.presto.grpc.api.udf.GrpcUtils.toGrpcSerializedPage)

Example 4 with GrpcUdfPage

use of com.facebook.presto.grpc.udf.GrpcUdfPage 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

GrpcUtils.toGrpcUdfPage (com.facebook.presto.grpc.api.udf.GrpcUtils.toGrpcUdfPage)4 GrpcUdfPage (com.facebook.presto.grpc.udf.GrpcUdfPage)4 Page (com.facebook.presto.common.Page)3 GrpcUtils.toGrpcSerializedPage (com.facebook.presto.grpc.api.udf.GrpcUtils.toGrpcSerializedPage)3 GrpcUtils.toPrestoPage (com.facebook.presto.grpc.api.udf.GrpcUtils.toPrestoPage)3 GrpcSerializedPage (com.facebook.presto.grpc.udf.GrpcSerializedPage)3 Block (com.facebook.presto.common.block.Block)1 SqlFunctionResult (com.facebook.presto.common.function.SqlFunctionResult)1 GrpcFunctionHandle (com.facebook.presto.grpc.udf.GrpcFunctionHandle)1 GrpcUdfRequest (com.facebook.presto.grpc.udf.GrpcUdfRequest)1 GrpcUdfResult (com.facebook.presto.grpc.udf.GrpcUdfResult)1 SqlFunctionHandle (com.facebook.presto.spi.function.SqlFunctionHandle)1 SqlFunctionId (com.facebook.presto.spi.function.SqlFunctionId)1