Search in sources :

Example 1 with SqlFunctionResult

use of com.facebook.presto.common.function.SqlFunctionResult in project presto by prestodb.

the class RemoteProjectOperator method addInput.

@Override
public void addInput(Page page) {
    checkState(!finishing, "Operator is already finishing");
    checkState(!processingPage(), "Still processing previous input");
    requireNonNull(page, "page is null");
    for (int channel = 0; channel < projections.size(); channel++) {
        RowExpression projection = projections.get(channel);
        if (projection instanceof InputReferenceExpression) {
            result[channel] = completedFuture(new SqlFunctionResult(page.getBlock(((InputReferenceExpression) projection).getField()), 0));
        } else if (projection instanceof CallExpression) {
            CallExpression remoteCall = (CallExpression) projection;
            result[channel] = functionAndTypeManager.executeFunction(operatorContext.getDriverContext().getTaskId().toString(), remoteCall.getFunctionHandle(), page, remoteCall.getArguments().stream().map(InputReferenceExpression.class::cast).map(InputReferenceExpression::getField).collect(toImmutableList()));
        } else {
            checkState(projection instanceof ConstantExpression, format("Does not expect expression type %s", projection.getClass()));
        }
    }
}
Also used : InputReferenceExpression(com.facebook.presto.spi.relation.InputReferenceExpression) ConstantExpression(com.facebook.presto.spi.relation.ConstantExpression) RowExpression(com.facebook.presto.spi.relation.RowExpression) SqlFunctionResult(com.facebook.presto.common.function.SqlFunctionResult) CallExpression(com.facebook.presto.spi.relation.CallExpression)

Example 2 with SqlFunctionResult

use of com.facebook.presto.common.function.SqlFunctionResult 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 3 with SqlFunctionResult

use of com.facebook.presto.common.function.SqlFunctionResult in project presto by prestodb.

the class ThriftSqlFunctionExecutor method toSqlFunctionResult.

private SqlFunctionResult toSqlFunctionResult(ThriftUdfResult result, Type returnType) {
    ThriftUdfPage page = result.getResult();
    switch(page.getPageFormat()) {
        case PRESTO_THRIFT:
            return new SqlFunctionResult(getOnlyElement(page.getThriftPage().getThriftBlocks()).toBlock(returnType), result.getUdfStats().getTotalCpuTimeMs());
        case PRESTO_SERIALIZED:
            checkState(blockEncodingSerde != null, "blockEncodingSerde not set");
            PagesSerde pagesSerde = new PagesSerde(blockEncodingSerde, Optional.empty(), Optional.empty(), Optional.empty());
            return new SqlFunctionResult(pagesSerde.deserialize(page.getPrestoPage().toSerializedPage()).getBlock(0), result.getUdfStats().getTotalCpuTimeMs());
        default:
            throw new IllegalArgumentException(format("Unknown page format: %s", page.getPageFormat()));
    }
}
Also used : PagesSerde(com.facebook.presto.spi.page.PagesSerde) ThriftUdfPage(com.facebook.presto.thrift.api.udf.ThriftUdfPage) SqlFunctionResult(com.facebook.presto.common.function.SqlFunctionResult)

Aggregations

SqlFunctionResult (com.facebook.presto.common.function.SqlFunctionResult)3 Page (com.facebook.presto.common.Page)1 GrpcUtils.toGrpcSerializedPage (com.facebook.presto.grpc.api.udf.GrpcUtils.toGrpcSerializedPage)1 GrpcUtils.toGrpcUdfPage (com.facebook.presto.grpc.api.udf.GrpcUtils.toGrpcUdfPage)1 GrpcUtils.toPrestoPage (com.facebook.presto.grpc.api.udf.GrpcUtils.toPrestoPage)1 GrpcSerializedPage (com.facebook.presto.grpc.udf.GrpcSerializedPage)1 GrpcUdfPage (com.facebook.presto.grpc.udf.GrpcUdfPage)1 PagesSerde (com.facebook.presto.spi.page.PagesSerde)1 CallExpression (com.facebook.presto.spi.relation.CallExpression)1 ConstantExpression (com.facebook.presto.spi.relation.ConstantExpression)1 InputReferenceExpression (com.facebook.presto.spi.relation.InputReferenceExpression)1 RowExpression (com.facebook.presto.spi.relation.RowExpression)1 ThriftUdfPage (com.facebook.presto.thrift.api.udf.ThriftUdfPage)1