Search in sources :

Example 1 with ThriftUdfResult

use of com.facebook.presto.thrift.api.udf.ThriftUdfResult in project presto by prestodb.

the class ThriftSqlFunctionExecutor method invokeUdfWithRetry.

private static CompletableFuture<ThriftUdfResult> invokeUdfWithRetry(ThriftUdfService thriftUdfService, ThriftUdfRequest request) {
    CompletableFuture<ThriftUdfResult> resultFuture = invokeUdf(thriftUdfService, request);
    for (int i = 0; i < DEFAULT_RETRY_ATTEMPTS; i++) {
        resultFuture = resultFuture.thenApply(CompletableFuture::completedFuture).exceptionally(t -> {
            Throwable e = t.getCause();
            if (e instanceof PrestoException) {
                throw (PrestoException) e;
            }
            if (e instanceof ThriftUdfServiceException && ((ThriftUdfServiceException) e).isRetryable()) {
                return invokeUdf(thriftUdfService, request);
            }
            PrestoException prestoException = e instanceof ThriftUdfServiceException ? toPrestoException((ThriftUdfServiceException) e) : new PrestoException(GENERIC_INTERNAL_ERROR, e);
            throw prestoException;
        }).thenCompose(identity());
    }
    return resultFuture;
}
Also used : ThriftUdfServiceException(com.facebook.presto.thrift.api.udf.ThriftUdfServiceException) ThriftUdfResult(com.facebook.presto.thrift.api.udf.ThriftUdfResult) PrestoException(com.facebook.presto.spi.PrestoException) ExceptionUtils.toPrestoException(com.facebook.presto.functionNamespace.execution.ExceptionUtils.toPrestoException)

Example 2 with ThriftUdfResult

use of com.facebook.presto.thrift.api.udf.ThriftUdfResult in project presto by prestodb.

the class EchoFirstInputThriftUdfService method invokeUdf.

@Override
public ListenableFuture<ThriftUdfResult> invokeUdf(ThriftUdfRequest request) throws ThriftUdfServiceException {
    ThriftUdfPage inputs = request.getInputs();
    ThriftUdfPage result;
    switch(inputs.getPageFormat()) {
        case PRESTO_THRIFT:
            PrestoThriftPage thriftPage = inputs.getThriftPage();
            if (thriftPage.getThriftBlocks().isEmpty()) {
                throw toThriftUdfServiceException(false, EchoFirstInputErrorCode.GENERIC_INTERNAL_ERROR.toErrorCode(), new UnsupportedOperationException("No input to echo"));
            }
            result = thriftPage(new PrestoThriftPage(ImmutableList.of(thriftPage.getThriftBlocks().get(0)), inputs.getThriftPage().getPositionCount()));
            break;
        case PRESTO_SERIALIZED:
            PagesSerde pagesSerde = new PagesSerde(blockEncodingSerde, Optional.empty(), Optional.empty(), Optional.empty());
            Page page = pagesSerde.deserialize(inputs.getPrestoPage().toSerializedPage());
            if (page.getChannelCount() == 0) {
                throw toThriftUdfServiceException(false, EchoFirstInputErrorCode.GENERIC_INTERNAL_ERROR.toErrorCode(), new UnsupportedOperationException("No input to echo"));
            }
            result = prestoPage(pagesSerde.serialize(new Page(page.getBlock(0))));
            break;
        default:
            throw new UnsupportedOperationException();
    }
    return immediateFuture(new ThriftUdfResult(result, new ThriftUdfStats(100)));
}
Also used : PrestoThriftPage(com.facebook.presto.thrift.api.udf.PrestoThriftPage) PagesSerde(com.facebook.presto.spi.page.PagesSerde) ThriftUdfStats(com.facebook.presto.thrift.api.udf.ThriftUdfStats) Page(com.facebook.presto.common.Page) ThriftUdfPage(com.facebook.presto.thrift.api.udf.ThriftUdfPage) ThriftUdfPage.prestoPage(com.facebook.presto.thrift.api.udf.ThriftUdfPage.prestoPage) ThriftUdfPage.thriftPage(com.facebook.presto.thrift.api.udf.ThriftUdfPage.thriftPage) PrestoThriftPage(com.facebook.presto.thrift.api.udf.PrestoThriftPage) ThriftUdfResult(com.facebook.presto.thrift.api.udf.ThriftUdfResult) ThriftUdfPage(com.facebook.presto.thrift.api.udf.ThriftUdfPage)

Aggregations

ThriftUdfResult (com.facebook.presto.thrift.api.udf.ThriftUdfResult)2 Page (com.facebook.presto.common.Page)1 ExceptionUtils.toPrestoException (com.facebook.presto.functionNamespace.execution.ExceptionUtils.toPrestoException)1 PrestoException (com.facebook.presto.spi.PrestoException)1 PagesSerde (com.facebook.presto.spi.page.PagesSerde)1 PrestoThriftPage (com.facebook.presto.thrift.api.udf.PrestoThriftPage)1 ThriftUdfPage (com.facebook.presto.thrift.api.udf.ThriftUdfPage)1 ThriftUdfPage.prestoPage (com.facebook.presto.thrift.api.udf.ThriftUdfPage.prestoPage)1 ThriftUdfPage.thriftPage (com.facebook.presto.thrift.api.udf.ThriftUdfPage.thriftPage)1 ThriftUdfServiceException (com.facebook.presto.thrift.api.udf.ThriftUdfServiceException)1 ThriftUdfStats (com.facebook.presto.thrift.api.udf.ThriftUdfStats)1