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));
}
}
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();
}
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();
}
Aggregations