Search in sources :

Example 1 with QueryException

use of com.facebook.presto.verifier.framework.QueryException in project presto by prestodb.

the class PrestoExceptionClassifier method shouldResubmit.

public boolean shouldResubmit(Throwable throwable) {
    if (!(throwable instanceof PrestoQueryException)) {
        return false;
    }
    PrestoQueryException queryException = (PrestoQueryException) throwable;
    Optional<ErrorCodeSupplier> errorCode = queryException.getErrorCode();
    return errorCode.isPresent() && (resubmittedErrors.contains(errorCode.get()) || conditionalResubmittedErrors.stream().anyMatch(matcher -> matcher.matches(errorCode.get(), queryException.getQueryStage(), queryException.getMessage())));
}
Also used : ThrottlingException(com.facebook.presto.verifier.framework.ThrottlingException) HIVE_CURSOR_ERROR(com.facebook.presto.hive.HiveErrorCode.HIVE_CURSOR_ERROR) TimeoutException(java.util.concurrent.TimeoutException) SERVER_SHUTTING_DOWN(com.facebook.presto.spi.StandardErrorCode.SERVER_SHUTTING_DOWN) CASE_INSENSITIVE(java.util.regex.Pattern.CASE_INSENSITIVE) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) HIVE_METASTORE_ERROR(com.facebook.presto.hive.HiveErrorCode.HIVE_METASTORE_ERROR) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) ABANDONED_TASK(com.facebook.presto.spi.StandardErrorCode.ABANDONED_TASK) EXCEEDED_TIME_LIMIT(com.facebook.presto.spi.StandardErrorCode.EXCEEDED_TIME_LIMIT) Functions.identity(com.google.common.base.Functions.identity) ImmutableSet(com.google.common.collect.ImmutableSet) HIVE_WRITER_DATA_ERROR(com.facebook.presto.hive.HiveErrorCode.HIVE_WRITER_DATA_ERROR) REMOTE_TASK_MISMATCH(com.facebook.presto.spi.StandardErrorCode.REMOTE_TASK_MISMATCH) HIVE_TOO_MANY_OPEN_PARTITIONS(com.facebook.presto.hive.HiveErrorCode.HIVE_TOO_MANY_OPEN_PARTITIONS) Set(java.util.Set) NO_NODES_AVAILABLE(com.facebook.presto.spi.StandardErrorCode.NO_NODES_AVAILABLE) PAGE_TRANSPORT_TIMEOUT(com.facebook.presto.spi.StandardErrorCode.PAGE_TRANSPORT_TIMEOUT) EOFException(java.io.EOFException) UncheckedIOException(java.io.UncheckedIOException) Objects(java.util.Objects) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) TOO_MANY_REQUESTS_FAILED(com.facebook.presto.spi.StandardErrorCode.TOO_MANY_REQUESTS_FAILED) StandardErrorCode(com.facebook.presto.spi.StandardErrorCode) HIVE_TABLE_DROPPED_DURING_QUERY(com.facebook.presto.hive.HiveErrorCode.HIVE_TABLE_DROPPED_DURING_QUERY) Optional(java.util.Optional) ErrorCodeSupplier(com.facebook.presto.spi.ErrorCodeSupplier) THRIFT_SERVICE_CONNECTION_ERROR(com.facebook.presto.connector.thrift.ThriftErrorCode.THRIFT_SERVICE_CONNECTION_ERROR) Pattern(java.util.regex.Pattern) MoreObjects.toStringHelper(com.google.common.base.MoreObjects.toStringHelper) HIVE_FILE_NOT_FOUND(com.facebook.presto.hive.HiveErrorCode.HIVE_FILE_NOT_FOUND) TEST_MAIN(com.facebook.presto.verifier.framework.QueryStage.TEST_MAIN) JDBC_ERROR(com.facebook.presto.plugin.jdbc.JdbcErrorCode.JDBC_ERROR) ThriftErrorCode(com.facebook.presto.connector.thrift.ThriftErrorCode) ClusterConnectionException(com.facebook.presto.verifier.framework.ClusterConnectionException) HIVE_PARTITION_DROPPED_DURING_QUERY(com.facebook.presto.hive.HiveErrorCode.HIVE_PARTITION_DROPPED_DURING_QUERY) HIVE_WRITER_CLOSE_ERROR(com.facebook.presto.hive.HiveErrorCode.HIVE_WRITER_CLOSE_ERROR) CLUSTER_OUT_OF_MEMORY(com.facebook.presto.spi.StandardErrorCode.CLUSTER_OUT_OF_MEMORY) HIVE_CANNOT_OPEN_SPLIT(com.facebook.presto.hive.HiveErrorCode.HIVE_CANNOT_OPEN_SPLIT) REMOTE_HOST_GONE(com.facebook.presto.spi.StandardErrorCode.REMOTE_HOST_GONE) SocketException(java.net.SocketException) SQLException(java.sql.SQLException) SocketTimeoutException(java.net.SocketTimeoutException) DESCRIBE(com.facebook.presto.verifier.framework.QueryStage.DESCRIBE) Objects.requireNonNull(java.util.Objects.requireNonNull) TEST_SETUP(com.facebook.presto.verifier.framework.QueryStage.TEST_SETUP) THRIFT_SERVICE_GENERIC_REMOTE_ERROR(com.facebook.presto.connector.thrift.ThriftErrorCode.THRIFT_SERVICE_GENERIC_REMOTE_ERROR) PAGE_TRANSPORT_ERROR(com.facebook.presto.spi.StandardErrorCode.PAGE_TRANSPORT_ERROR) HIVE_PARTITION_OFFLINE(com.facebook.presto.hive.HiveErrorCode.HIVE_PARTITION_OFFLINE) SERVER_STARTING_UP(com.facebook.presto.spi.StandardErrorCode.SERVER_STARTING_UP) JdbcErrorCode(com.facebook.presto.plugin.jdbc.JdbcErrorCode) ABANDONED_QUERY(com.facebook.presto.spi.StandardErrorCode.ABANDONED_QUERY) PrestoQueryException(com.facebook.presto.verifier.framework.PrestoQueryException) QueryException(com.facebook.presto.verifier.framework.QueryException) HIVE_FILESYSTEM_ERROR(com.facebook.presto.hive.HiveErrorCode.HIVE_FILESYSTEM_ERROR) REMOTE_TASK_ERROR(com.facebook.presto.spi.StandardErrorCode.REMOTE_TASK_ERROR) SYNTAX_ERROR(com.facebook.presto.spi.StandardErrorCode.SYNTAX_ERROR) ADMINISTRATIVELY_PREEMPTED(com.facebook.presto.spi.StandardErrorCode.ADMINISTRATIVELY_PREEMPTED) HiveErrorCode(com.facebook.presto.hive.HiveErrorCode) SparkErrorCode(com.facebook.presto.spark.SparkErrorCode) CONTROL_SETUP(com.facebook.presto.verifier.framework.QueryStage.CONTROL_SETUP) HIVE_WRITER_OPEN_ERROR(com.facebook.presto.hive.HiveErrorCode.HIVE_WRITER_OPEN_ERROR) QueryStage(com.facebook.presto.verifier.framework.QueryStage) PrestoQueryException(com.facebook.presto.verifier.framework.PrestoQueryException) ErrorCodeSupplier(com.facebook.presto.spi.ErrorCodeSupplier)

Example 2 with QueryException

use of com.facebook.presto.verifier.framework.QueryException in project presto by prestodb.

the class TooManyOpenPartitionsFailureResolver method resolveQueryFailure.

@Override
public Optional<String> resolveQueryFailure(QueryStats controlQueryStats, QueryException queryException, Optional<QueryObjectBundle> test) {
    if (!test.isPresent()) {
        return Optional.empty();
    }
    return mapMatchingPrestoException(queryException, TEST_MAIN, ImmutableSet.of(HIVE_TOO_MANY_OPEN_PARTITIONS), e -> {
        try {
            ShowCreate showCreate = new ShowCreate(TABLE, test.get().getObjectName());
            String showCreateResult = getOnlyElement(prestoAction.execute(showCreate, DESCRIBE, resultSet -> Optional.of(resultSet.getString(1))).getResults());
            CreateTable createTable = (CreateTable) sqlParser.createStatement(showCreateResult, ParsingOptions.builder().setDecimalLiteralTreatment(AS_DOUBLE).build());
            List<Property> bucketCountProperty = createTable.getProperties().stream().filter(property -> property.getName().getValue().equals(BUCKET_COUNT_PROPERTY)).collect(toImmutableList());
            if (bucketCountProperty.size() != 1) {
                return Optional.empty();
            }
            long bucketCount = ((LongLiteral) getOnlyElement(bucketCountProperty).getValue()).getValue();
            int testClusterSize = this.testClusterSizeSupplier.get();
            if (testClusterSize * maxBucketPerWriter < bucketCount) {
                return Optional.of("Not enough workers on test cluster");
            }
            return Optional.empty();
        } catch (Throwable t) {
            log.warn(t, "Exception when resolving HIVE_TOO_MANY_OPEN_PARTITIONS");
            return Optional.empty();
        }
    });
}
Also used : Logger(com.facebook.airlift.log.Logger) TEST_MAIN(com.facebook.presto.verifier.framework.QueryStage.TEST_MAIN) Suppliers.memoizeWithExpiration(com.google.common.base.Suppliers.memoizeWithExpiration) Supplier(java.util.function.Supplier) Duration(io.airlift.units.Duration) Inject(javax.inject.Inject) QueryObjectBundle(com.facebook.presto.verifier.framework.QueryObjectBundle) DESCRIBE(com.facebook.presto.verifier.framework.QueryStage.DESCRIBE) Objects.requireNonNull(java.util.Objects.requireNonNull) QueryStats(com.facebook.presto.jdbc.QueryStats) CreateTable(com.facebook.presto.sql.tree.CreateTable) ForTest(com.facebook.presto.verifier.annotation.ForTest) Property(com.facebook.presto.sql.tree.Property) ImmutableSet(com.google.common.collect.ImmutableSet) FailureResolverUtil.mapMatchingPrestoException(com.facebook.presto.verifier.resolver.FailureResolverUtil.mapMatchingPrestoException) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) HIVE_TOO_MANY_OPEN_PARTITIONS(com.facebook.presto.hive.HiveErrorCode.HIVE_TOO_MANY_OPEN_PARTITIONS) Iterables.getOnlyElement(com.google.common.collect.Iterables.getOnlyElement) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) SqlParser(com.facebook.presto.sql.parser.SqlParser) QueryException(com.facebook.presto.verifier.framework.QueryException) List(java.util.List) AS_DOUBLE(com.facebook.presto.sql.parser.ParsingOptions.DecimalLiteralTreatment.AS_DOUBLE) BUCKET_COUNT_PROPERTY(com.facebook.presto.hive.HiveTableProperties.BUCKET_COUNT_PROPERTY) ShowCreate(com.facebook.presto.sql.tree.ShowCreate) PrestoAction(com.facebook.presto.verifier.prestoaction.PrestoAction) LongLiteral(com.facebook.presto.sql.tree.LongLiteral) Optional(java.util.Optional) ParsingOptions(com.facebook.presto.sql.parser.ParsingOptions) TABLE(com.facebook.presto.sql.tree.ShowCreate.Type.TABLE) LongLiteral(com.facebook.presto.sql.tree.LongLiteral) ShowCreate(com.facebook.presto.sql.tree.ShowCreate) CreateTable(com.facebook.presto.sql.tree.CreateTable) Property(com.facebook.presto.sql.tree.Property)

Example 3 with QueryException

use of com.facebook.presto.verifier.framework.QueryException in project presto by prestodb.

the class QueryRewriter method rewriteQuery.

public QueryObjectBundle rewriteQuery(@Language("SQL") String query, ClusterType clusterType) {
    checkState(prefixes.containsKey(clusterType), "Unsupported cluster type: %s", clusterType);
    Statement statement = sqlParser.createStatement(query, PARSING_OPTIONS);
    QualifiedName prefix = prefixes.get(clusterType);
    List<Property> properties = tableProperties.get(clusterType);
    if (statement instanceof CreateTableAsSelect) {
        CreateTableAsSelect createTableAsSelect = (CreateTableAsSelect) statement;
        QualifiedName temporaryTableName = generateTemporaryName(Optional.of(createTableAsSelect.getName()), prefix);
        return new QueryObjectBundle(temporaryTableName, ImmutableList.of(), new CreateTableAsSelect(temporaryTableName, createTableAsSelect.getQuery(), createTableAsSelect.isNotExists(), applyPropertyOverride(createTableAsSelect.getProperties(), properties), createTableAsSelect.isWithData(), createTableAsSelect.getColumnAliases(), createTableAsSelect.getComment()), ImmutableList.of(new DropTable(temporaryTableName, true)), clusterType);
    }
    if (statement instanceof Insert) {
        Insert insert = (Insert) statement;
        QualifiedName originalTableName = insert.getTarget();
        QualifiedName temporaryTableName = generateTemporaryName(Optional.of(originalTableName), prefix);
        return new QueryObjectBundle(temporaryTableName, ImmutableList.of(new CreateTable(temporaryTableName, ImmutableList.of(new LikeClause(originalTableName, Optional.of(INCLUDING))), false, properties, Optional.empty())), new Insert(temporaryTableName, insert.getColumns(), insert.getQuery()), ImmutableList.of(new DropTable(temporaryTableName, true)), clusterType);
    }
    if (statement instanceof Query) {
        QualifiedName temporaryTableName = generateTemporaryName(Optional.empty(), prefix);
        ResultSetMetaData metadata = getResultMetadata((Query) statement);
        List<Identifier> columnAliases = generateStorageColumnAliases(metadata);
        Query rewrite = rewriteNonStorableColumns((Query) statement, metadata);
        return new QueryObjectBundle(temporaryTableName, ImmutableList.of(), new CreateTableAsSelect(temporaryTableName, rewrite, false, properties, true, Optional.of(columnAliases), Optional.empty()), ImmutableList.of(new DropTable(temporaryTableName, true)), clusterType);
    }
    if (statement instanceof CreateView) {
        CreateView createView = (CreateView) statement;
        QualifiedName temporaryViewName = generateTemporaryName(Optional.empty(), prefix);
        ImmutableList.Builder<Statement> setupQueries = ImmutableList.builder();
        // Otherwise, do not pre-create temporary view.
        try {
            String createExistingViewQuery = getOnlyElement(prestoAction.execute(new ShowCreate(VIEW, createView.getName()), REWRITE, SHOW_CREATE_VIEW_CONVERTER).getResults());
            CreateView createExistingView = (CreateView) sqlParser.createStatement(createExistingViewQuery, PARSING_OPTIONS);
            setupQueries.add(new CreateView(temporaryViewName, createExistingView.getQuery(), false, createExistingView.getSecurity()));
        } catch (QueryException e) {
        // no-op
        }
        return new QueryObjectBundle(temporaryViewName, setupQueries.build(), new CreateView(temporaryViewName, createView.getQuery(), createView.isReplace(), createView.getSecurity()), ImmutableList.of(new DropView(temporaryViewName, true)), clusterType);
    }
    if (statement instanceof CreateTable) {
        CreateTable createTable = (CreateTable) statement;
        QualifiedName temporaryTableName = generateTemporaryName(Optional.empty(), prefix);
        return new QueryObjectBundle(temporaryTableName, ImmutableList.of(), new CreateTable(temporaryTableName, createTable.getElements(), createTable.isNotExists(), applyPropertyOverride(createTable.getProperties(), properties), createTable.getComment()), ImmutableList.of(new DropTable(temporaryTableName, true)), clusterType);
    }
    throw new IllegalStateException(format("Unsupported query type: %s", statement.getClass()));
}
Also used : LikeClause(com.facebook.presto.sql.tree.LikeClause) Query(com.facebook.presto.sql.tree.Query) Statement(com.facebook.presto.sql.tree.Statement) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ImmutableList(com.google.common.collect.ImmutableList) QualifiedName(com.facebook.presto.sql.tree.QualifiedName) DropView(com.facebook.presto.sql.tree.DropView) CreateTable(com.facebook.presto.sql.tree.CreateTable) DropTable(com.facebook.presto.sql.tree.DropTable) Insert(com.facebook.presto.sql.tree.Insert) CreateView(com.facebook.presto.sql.tree.CreateView) ResultSetMetaData(java.sql.ResultSetMetaData) QueryException(com.facebook.presto.verifier.framework.QueryException) Identifier(com.facebook.presto.sql.tree.Identifier) ShowCreate(com.facebook.presto.sql.tree.ShowCreate) CreateTableAsSelect(com.facebook.presto.sql.tree.CreateTableAsSelect) QueryObjectBundle(com.facebook.presto.verifier.framework.QueryObjectBundle) Property(com.facebook.presto.sql.tree.Property)

Example 4 with QueryException

use of com.facebook.presto.verifier.framework.QueryException in project presto by prestodb.

the class TestRetryDriver method setup.

@BeforeMethod
public void setup() {
    verificationContext = VerificationContext.create(SUITE, NAME);
    retryDriver = new RetryDriver<>(new RetryConfig().setMaxAttempts(5).setMinBackoffDelay(new Duration(10, MILLISECONDS)).setMaxBackoffDelay(new Duration(100, MILLISECONDS)).setScaleFactor(2), QueryException::isRetryable, QueryException.class, verificationContext::addException);
}
Also used : PrestoQueryException(com.facebook.presto.verifier.framework.PrestoQueryException) QueryException(com.facebook.presto.verifier.framework.QueryException) Duration(io.airlift.units.Duration) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 5 with QueryException

use of com.facebook.presto.verifier.framework.QueryException in project presto by prestodb.

the class TestRetryDriver method testBackoffTimeCapped.

@Test(timeOut = 5000)
public void testBackoffTimeCapped() {
    RetryDriver retryDriver = new RetryDriver<>(new RetryConfig().setMaxAttempts(5).setMinBackoffDelay(new Duration(10, MILLISECONDS)).setMaxBackoffDelay(new Duration(100, MILLISECONDS)).setScaleFactor(1000), QueryException::isRetryable, QueryException.class, verificationContext::addException);
    retryDriver.run("test", new MockOperation(5, RETRYABLE_EXCEPTION));
}
Also used : PrestoQueryException(com.facebook.presto.verifier.framework.PrestoQueryException) QueryException(com.facebook.presto.verifier.framework.QueryException) Duration(io.airlift.units.Duration) Test(org.testng.annotations.Test)

Aggregations

QueryException (com.facebook.presto.verifier.framework.QueryException)5 PrestoQueryException (com.facebook.presto.verifier.framework.PrestoQueryException)3 Duration (io.airlift.units.Duration)3 HIVE_TOO_MANY_OPEN_PARTITIONS (com.facebook.presto.hive.HiveErrorCode.HIVE_TOO_MANY_OPEN_PARTITIONS)2 CreateTable (com.facebook.presto.sql.tree.CreateTable)2 Property (com.facebook.presto.sql.tree.Property)2 ShowCreate (com.facebook.presto.sql.tree.ShowCreate)2 QueryObjectBundle (com.facebook.presto.verifier.framework.QueryObjectBundle)2 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)2 Logger (com.facebook.airlift.log.Logger)1 ThriftErrorCode (com.facebook.presto.connector.thrift.ThriftErrorCode)1 THRIFT_SERVICE_CONNECTION_ERROR (com.facebook.presto.connector.thrift.ThriftErrorCode.THRIFT_SERVICE_CONNECTION_ERROR)1 THRIFT_SERVICE_GENERIC_REMOTE_ERROR (com.facebook.presto.connector.thrift.ThriftErrorCode.THRIFT_SERVICE_GENERIC_REMOTE_ERROR)1 HiveErrorCode (com.facebook.presto.hive.HiveErrorCode)1 HIVE_CANNOT_OPEN_SPLIT (com.facebook.presto.hive.HiveErrorCode.HIVE_CANNOT_OPEN_SPLIT)1 HIVE_CURSOR_ERROR (com.facebook.presto.hive.HiveErrorCode.HIVE_CURSOR_ERROR)1 HIVE_FILESYSTEM_ERROR (com.facebook.presto.hive.HiveErrorCode.HIVE_FILESYSTEM_ERROR)1 HIVE_FILE_NOT_FOUND (com.facebook.presto.hive.HiveErrorCode.HIVE_FILE_NOT_FOUND)1 HIVE_METASTORE_ERROR (com.facebook.presto.hive.HiveErrorCode.HIVE_METASTORE_ERROR)1 HIVE_PARTITION_DROPPED_DURING_QUERY (com.facebook.presto.hive.HiveErrorCode.HIVE_PARTITION_DROPPED_DURING_QUERY)1