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