Search in sources :

Example 1 with GrpcSerializedPage

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

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

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

the class GrpcUtils method toGrpcSerializedPage.

public static GrpcSerializedPage toGrpcSerializedPage(BlockEncodingSerde blockEncodingSerde, Page prestoPage) {
    PagesSerde pagesSerde = new PagesSerde(blockEncodingSerde, Optional.empty(), Optional.empty(), Optional.empty());
    SerializedPage serializedPage = pagesSerde.serialize(prestoPage);
    return GrpcSerializedPage.newBuilder().setSliceBytes(ByteString.copyFrom(serializedPage.getSlice().getBytes())).setPositionCount(serializedPage.getPositionCount()).setUncompressedSizeInBytes(serializedPage.getUncompressedSizeInBytes()).setPageCodecMarkers(ByteString.copyFrom(new byte[] { serializedPage.getPageCodecMarkers() })).setChecksum(serializedPage.getChecksum()).build();
}
Also used : PagesSerde(com.facebook.presto.spi.page.PagesSerde) GrpcSerializedPage(com.facebook.presto.grpc.udf.GrpcSerializedPage) SerializedPage(com.facebook.presto.spi.page.SerializedPage)

Aggregations

GrpcSerializedPage (com.facebook.presto.grpc.udf.GrpcSerializedPage)3 Page (com.facebook.presto.common.Page)2 GrpcUtils.toGrpcSerializedPage (com.facebook.presto.grpc.api.udf.GrpcUtils.toGrpcSerializedPage)2 GrpcUtils.toGrpcUdfPage (com.facebook.presto.grpc.api.udf.GrpcUtils.toGrpcUdfPage)2 GrpcUtils.toPrestoPage (com.facebook.presto.grpc.api.udf.GrpcUtils.toPrestoPage)2 GrpcUdfPage (com.facebook.presto.grpc.udf.GrpcUdfPage)2 Block (com.facebook.presto.common.block.Block)1 GrpcUdfResult (com.facebook.presto.grpc.udf.GrpcUdfResult)1 PagesSerde (com.facebook.presto.spi.page.PagesSerde)1 SerializedPage (com.facebook.presto.spi.page.SerializedPage)1