Search in sources :

Example 1 with ChecksumValidator

use of com.facebook.presto.verifier.checksum.ChecksumValidator in project presto by prestodb.

the class DeterminismAnalyzer method analyze.

private DeterminismAnalysis analyze(QueryObjectBundle control, ChecksumResult controlChecksum, DeterminismAnalysisDetails.Builder determinismAnalysisDetails) {
    // Handle mutable catalogs
    if (isNonDeterministicCatalogReferenced(control.getQuery())) {
        return NON_DETERMINISTIC_CATALOG;
    }
    // Handle limit query
    LimitQueryDeterminismAnalysis limitQueryAnalysis = new LimitQueryDeterminismAnalyzer(prestoAction, handleLimitQuery, control.getQuery(), controlChecksum.getRowCount(), determinismAnalysisDetails).analyze();
    switch(limitQueryAnalysis) {
        case NOT_RUN:
        case FAILED_QUERY_FAILURE:
        case DETERMINISTIC:
            // try the next analysis
            break;
        case NON_DETERMINISTIC:
            return NON_DETERMINISTIC_LIMIT_CLAUSE;
        case FAILED_DATA_CHANGED:
            return ANALYSIS_FAILED_DATA_CHANGED;
        default:
            throw new IllegalArgumentException(format("Invalid limitQueryAnalysis: %s", limitQueryAnalysis));
    }
    // Rerun control query multiple times
    List<Column> columns = getColumns(prestoAction, typeManager, control.getObjectName());
    Map<QueryBundle, DeterminismAnalysisRun.Builder> queryRuns = new HashMap<>();
    try {
        for (int i = 0; i < maxAnalysisRuns; i++) {
            QueryObjectBundle queryBundle = queryRewriter.rewriteQuery(sourceQuery.getQuery(CONTROL), CONTROL);
            DeterminismAnalysisRun.Builder run = determinismAnalysisDetails.addRun().setTableName(queryBundle.getObjectName().toString());
            queryRuns.put(queryBundle, run);
            // Rerun setup and main query
            queryBundle.getSetupQueries().forEach(query -> runAndConsume(() -> prestoAction.execute(query, DETERMINISM_ANALYSIS_SETUP), stats -> stats.getQueryStats().map(QueryStats::getQueryId).ifPresent(run::addSetupQueryId)));
            runAndConsume(() -> prestoAction.execute(queryBundle.getQuery(), DETERMINISM_ANALYSIS_MAIN), stats -> stats.getQueryStats().map(QueryStats::getQueryId).ifPresent(run::setQueryId));
            // Run checksum query
            Query checksumQuery = checksumValidator.generateChecksumQuery(queryBundle.getObjectName(), columns);
            ChecksumResult testChecksum = getOnlyElement(callAndConsume(() -> prestoAction.execute(checksumQuery, DETERMINISM_ANALYSIS_CHECKSUM, ChecksumResult::fromResultSet), stats -> stats.getQueryStats().map(QueryStats::getQueryId).ifPresent(run::setChecksumQueryId)).getResults());
            DeterminismAnalysis analysis = matchResultToDeterminism(match(checksumValidator, columns, columns, controlChecksum, testChecksum));
            if (analysis != DETERMINISTIC) {
                return analysis;
            }
        }
        return DETERMINISTIC;
    } catch (QueryException qe) {
        return ANALYSIS_FAILED_QUERY_FAILURE;
    } finally {
        if (runTeardown) {
            queryRuns.forEach((queryBundle, run) -> teardownSafely(prestoAction, Optional.of(queryBundle), queryStats -> queryStats.getQueryStats().map(QueryStats::getQueryId).ifPresent(run::addTeardownQueryId)));
        }
    }
}
Also used : NON_DETERMINISTIC_ROW_COUNT(com.facebook.presto.verifier.framework.DeterminismAnalysis.NON_DETERMINISTIC_ROW_COUNT) Table(com.facebook.presto.sql.tree.Table) DataVerificationUtil.match(com.facebook.presto.verifier.framework.DataVerificationUtil.match) ANALYSIS_FAILED_DATA_CHANGED(com.facebook.presto.verifier.framework.DeterminismAnalysis.ANALYSIS_FAILED_DATA_CHANGED) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) DETERMINISTIC(com.facebook.presto.verifier.framework.DeterminismAnalysis.DETERMINISTIC) VerifierUtil.callAndConsume(com.facebook.presto.verifier.framework.VerifierUtil.callAndConsume) NON_DETERMINISTIC_CATALOG(com.facebook.presto.verifier.framework.DeterminismAnalysis.NON_DETERMINISTIC_CATALOG) NON_DETERMINISTIC_COLUMNS(com.facebook.presto.verifier.framework.DeterminismAnalysis.NON_DETERMINISTIC_COLUMNS) DataVerificationUtil.getColumns(com.facebook.presto.verifier.framework.DataVerificationUtil.getColumns) TypeManager(com.facebook.presto.common.type.TypeManager) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) QueryStats(com.facebook.presto.jdbc.QueryStats) ANALYSIS_FAILED_INCONSISTENT_SCHEMA(com.facebook.presto.verifier.framework.DeterminismAnalysis.ANALYSIS_FAILED_INCONSISTENT_SCHEMA) QueryRewriter(com.facebook.presto.verifier.rewrite.QueryRewriter) DETERMINISM_ANALYSIS_SETUP(com.facebook.presto.verifier.framework.QueryStage.DETERMINISM_ANALYSIS_SETUP) DeterminismAnalysisRun(com.facebook.presto.verifier.event.DeterminismAnalysisRun) ANALYSIS_FAILED_QUERY_FAILURE(com.facebook.presto.verifier.framework.DeterminismAnalysis.ANALYSIS_FAILED_QUERY_FAILURE) DETERMINISM_ANALYSIS_CHECKSUM(com.facebook.presto.verifier.framework.QueryStage.DETERMINISM_ANALYSIS_CHECKSUM) ImmutableSet(com.google.common.collect.ImmutableSet) DataVerificationUtil.teardownSafely(com.facebook.presto.verifier.framework.DataVerificationUtil.teardownSafely) Query(com.facebook.presto.sql.tree.Query) Node(com.facebook.presto.sql.tree.Node) AstVisitor(com.facebook.presto.sql.tree.AstVisitor) Set(java.util.Set) Iterables.getOnlyElement(com.google.common.collect.Iterables.getOnlyElement) CONTROL(com.facebook.presto.verifier.framework.ClusterType.CONTROL) String.format(java.lang.String.format) ChecksumResult(com.facebook.presto.verifier.checksum.ChecksumResult) DeterminismAnalysisDetails(com.facebook.presto.verifier.event.DeterminismAnalysisDetails) List(java.util.List) VerifierUtil.runAndConsume(com.facebook.presto.verifier.framework.VerifierUtil.runAndConsume) ChecksumValidator(com.facebook.presto.verifier.checksum.ChecksumValidator) PrestoAction(com.facebook.presto.verifier.prestoaction.PrestoAction) Optional(java.util.Optional) VisibleForTesting(com.google.common.annotations.VisibleForTesting) NON_DETERMINISTIC_LIMIT_CLAUSE(com.facebook.presto.verifier.framework.DeterminismAnalysis.NON_DETERMINISTIC_LIMIT_CLAUSE) DETERMINISM_ANALYSIS_MAIN(com.facebook.presto.verifier.framework.QueryStage.DETERMINISM_ANALYSIS_MAIN) Statement(com.facebook.presto.sql.tree.Statement) ChecksumResult(com.facebook.presto.verifier.checksum.ChecksumResult) Query(com.facebook.presto.sql.tree.Query) HashMap(java.util.HashMap) QueryStats(com.facebook.presto.jdbc.QueryStats) DeterminismAnalysisRun(com.facebook.presto.verifier.event.DeterminismAnalysisRun)

Example 2 with ChecksumValidator

use of com.facebook.presto.verifier.checksum.ChecksumValidator in project presto by prestodb.

the class TestDeterminismAnalyzer method createDeterminismAnalyzer.

private static DeterminismAnalyzer createDeterminismAnalyzer(String mutableCatalogPattern) {
    QueryConfiguration configuration = new QueryConfiguration(CATALOG, SCHEMA, Optional.of("user"), Optional.empty(), Optional.empty());
    VerificationContext verificationContext = VerificationContext.create(SUITE, NAME);
    VerifierConfig verifierConfig = new VerifierConfig().setTestId("test-id");
    RetryConfig retryConfig = new RetryConfig();
    QueryActionsConfig queryActionsConfig = new QueryActionsConfig();
    TypeManager typeManager = createTypeManager();
    PrestoAction prestoAction = new JdbcPrestoAction(PrestoExceptionClassifier.defaultBuilder().build(), configuration, verificationContext, new JdbcUrlSelector(ImmutableList.of()), new PrestoActionConfig(), queryActionsConfig.getMetadataTimeout(), queryActionsConfig.getChecksumTimeout(), retryConfig, retryConfig, verifierConfig);
    QueryRewriter queryRewriter = new QueryRewriter(sqlParser, typeManager, prestoAction, ImmutableMap.of(CONTROL, QualifiedName.of("tmp_verifier_c"), TEST, QualifiedName.of("tmp_verifier_t")), ImmutableMap.of());
    ChecksumValidator checksumValidator = createChecksumValidator(verifierConfig);
    SourceQuery sourceQuery = new SourceQuery("test", "", "", "", configuration, configuration);
    return new DeterminismAnalyzer(sourceQuery, prestoAction, queryRewriter, checksumValidator, typeManager, new DeterminismAnalyzerConfig().setNonDeterministicCatalogs(mutableCatalogPattern));
}
Also used : QueryActionsConfig(com.facebook.presto.verifier.prestoaction.QueryActionsConfig) JdbcPrestoAction(com.facebook.presto.verifier.prestoaction.JdbcPrestoAction) PrestoAction(com.facebook.presto.verifier.prestoaction.PrestoAction) PrestoActionConfig(com.facebook.presto.verifier.prestoaction.PrestoActionConfig) QueryRewriter(com.facebook.presto.verifier.rewrite.QueryRewriter) JdbcPrestoAction(com.facebook.presto.verifier.prestoaction.JdbcPrestoAction) RetryConfig(com.facebook.presto.verifier.retry.RetryConfig) TypeManager(com.facebook.presto.common.type.TypeManager) VerifierTestUtil.createTypeManager(com.facebook.presto.verifier.VerifierTestUtil.createTypeManager) VerifierTestUtil.createChecksumValidator(com.facebook.presto.verifier.VerifierTestUtil.createChecksumValidator) ChecksumValidator(com.facebook.presto.verifier.checksum.ChecksumValidator) JdbcUrlSelector(com.facebook.presto.verifier.prestoaction.JdbcUrlSelector)

Example 3 with ChecksumValidator

use of com.facebook.presto.verifier.checksum.ChecksumValidator in project presto by prestodb.

the class VerifierTestUtil method createChecksumValidator.

public static ChecksumValidator createChecksumValidator(VerifierConfig verifierConfig) {
    Map<Column.Category, Provider<ColumnValidator>> lazyValidators = new HashMap<>();
    Map<Column.Category, Provider<ColumnValidator>> validators = ImmutableMap.of(Column.Category.SIMPLE, SimpleColumnValidator::new, Column.Category.FLOATING_POINT, () -> new FloatingPointColumnValidator(verifierConfig), Column.Category.ARRAY, ArrayColumnValidator::new, Column.Category.ROW, () -> new RowColumnValidator(lazyValidators), Column.Category.MAP, MapColumnValidator::new);
    lazyValidators.putAll(validators);
    return new ChecksumValidator(validators);
}
Also used : HashMap(java.util.HashMap) ArrayColumnValidator(com.facebook.presto.verifier.checksum.ArrayColumnValidator) MapColumnValidator(com.facebook.presto.verifier.checksum.MapColumnValidator) ChecksumValidator(com.facebook.presto.verifier.checksum.ChecksumValidator) FloatingPointColumnValidator(com.facebook.presto.verifier.checksum.FloatingPointColumnValidator) RowColumnValidator(com.facebook.presto.verifier.checksum.RowColumnValidator) SimpleColumnValidator(com.facebook.presto.verifier.checksum.SimpleColumnValidator) Provider(javax.inject.Provider)

Aggregations

ChecksumValidator (com.facebook.presto.verifier.checksum.ChecksumValidator)3 TypeManager (com.facebook.presto.common.type.TypeManager)2 PrestoAction (com.facebook.presto.verifier.prestoaction.PrestoAction)2 QueryRewriter (com.facebook.presto.verifier.rewrite.QueryRewriter)2 QueryStats (com.facebook.presto.jdbc.QueryStats)1 AstVisitor (com.facebook.presto.sql.tree.AstVisitor)1 Node (com.facebook.presto.sql.tree.Node)1 Query (com.facebook.presto.sql.tree.Query)1 Statement (com.facebook.presto.sql.tree.Statement)1 Table (com.facebook.presto.sql.tree.Table)1 VerifierTestUtil.createChecksumValidator (com.facebook.presto.verifier.VerifierTestUtil.createChecksumValidator)1 VerifierTestUtil.createTypeManager (com.facebook.presto.verifier.VerifierTestUtil.createTypeManager)1 ArrayColumnValidator (com.facebook.presto.verifier.checksum.ArrayColumnValidator)1 ChecksumResult (com.facebook.presto.verifier.checksum.ChecksumResult)1 FloatingPointColumnValidator (com.facebook.presto.verifier.checksum.FloatingPointColumnValidator)1 MapColumnValidator (com.facebook.presto.verifier.checksum.MapColumnValidator)1 RowColumnValidator (com.facebook.presto.verifier.checksum.RowColumnValidator)1 SimpleColumnValidator (com.facebook.presto.verifier.checksum.SimpleColumnValidator)1 DeterminismAnalysisDetails (com.facebook.presto.verifier.event.DeterminismAnalysisDetails)1 DeterminismAnalysisRun (com.facebook.presto.verifier.event.DeterminismAnalysisRun)1