Search in sources :

Example 1 with AS_DOUBLE

use of com.facebook.presto.sql.parser.ParsingOptions.DecimalLiteralTreatment.AS_DOUBLE 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)

Aggregations

Logger (com.facebook.airlift.log.Logger)1 HIVE_TOO_MANY_OPEN_PARTITIONS (com.facebook.presto.hive.HiveErrorCode.HIVE_TOO_MANY_OPEN_PARTITIONS)1 BUCKET_COUNT_PROPERTY (com.facebook.presto.hive.HiveTableProperties.BUCKET_COUNT_PROPERTY)1 QueryStats (com.facebook.presto.jdbc.QueryStats)1 ParsingOptions (com.facebook.presto.sql.parser.ParsingOptions)1 AS_DOUBLE (com.facebook.presto.sql.parser.ParsingOptions.DecimalLiteralTreatment.AS_DOUBLE)1 SqlParser (com.facebook.presto.sql.parser.SqlParser)1 CreateTable (com.facebook.presto.sql.tree.CreateTable)1 LongLiteral (com.facebook.presto.sql.tree.LongLiteral)1 Property (com.facebook.presto.sql.tree.Property)1 ShowCreate (com.facebook.presto.sql.tree.ShowCreate)1 TABLE (com.facebook.presto.sql.tree.ShowCreate.Type.TABLE)1 ForTest (com.facebook.presto.verifier.annotation.ForTest)1 QueryException (com.facebook.presto.verifier.framework.QueryException)1 QueryObjectBundle (com.facebook.presto.verifier.framework.QueryObjectBundle)1 DESCRIBE (com.facebook.presto.verifier.framework.QueryStage.DESCRIBE)1 TEST_MAIN (com.facebook.presto.verifier.framework.QueryStage.TEST_MAIN)1 PrestoAction (com.facebook.presto.verifier.prestoaction.PrestoAction)1 FailureResolverUtil.mapMatchingPrestoException (com.facebook.presto.verifier.resolver.FailureResolverUtil.mapMatchingPrestoException)1 Suppliers.memoizeWithExpiration (com.google.common.base.Suppliers.memoizeWithExpiration)1