Search in sources :

Example 1 with ThriftUdfServiceException

use of com.facebook.presto.thrift.api.udf.ThriftUdfServiceException 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 ThriftUdfServiceException

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

the class ExceptionUtils method toPrestoException.

public static PrestoException toPrestoException(ThriftUdfServiceException thriftException) {
    ThriftUdfServiceException exception = formatException(thriftException);
    PrestoException prestoException = new PrestoException(toThriftUdfErrorCodeSupplier(thriftException.getErrorCode()), exception);
    return prestoException;
}
Also used : ThriftUdfServiceException(com.facebook.presto.thrift.api.udf.ThriftUdfServiceException) PrestoException(com.facebook.presto.spi.PrestoException)

Aggregations

PrestoException (com.facebook.presto.spi.PrestoException)2 ThriftUdfServiceException (com.facebook.presto.thrift.api.udf.ThriftUdfServiceException)2 ExceptionUtils.toPrestoException (com.facebook.presto.functionNamespace.execution.ExceptionUtils.toPrestoException)1 ThriftUdfResult (com.facebook.presto.thrift.api.udf.ThriftUdfResult)1