use of com.facebook.presto.verifier.prestoaction.QueryAction in project presto by prestodb.
the class AbstractVerification method run.
@Override
public VerificationResult run() {
Optional<B> control = Optional.empty();
Optional<B> test = Optional.empty();
Optional<QueryResult<V>> controlQueryResult = Optional.empty();
Optional<QueryResult<V>> testQueryResult = Optional.empty();
QueryContext controlQueryContext = new QueryContext();
QueryContext testQueryContext = new QueryContext();
ChecksumQueryContext controlChecksumQueryContext = new ChecksumQueryContext();
ChecksumQueryContext testChecksumQueryContext = new ChecksumQueryContext();
Optional<R> matchResult = Optional.empty();
Optional<DeterminismAnalysisDetails> determinismAnalysisDetails = Optional.empty();
Optional<PartialVerificationResult> partialResult = Optional.empty();
Optional<Throwable> throwable = Optional.empty();
try {
// Rewrite queries
if (!skipControl) {
control = Optional.of(getQueryRewrite(CONTROL));
}
test = Optional.of(getQueryRewrite(TEST));
// Run control queries
if (!skipControl) {
QueryBundle controlQueryBundle = control.get();
QueryAction controlSetupAction = setupOnMainClusters ? queryActions.getControlAction() : queryActions.getHelperAction();
controlQueryBundle.getSetupQueries().forEach(query -> runAndConsume(() -> controlSetupAction.execute(query, CONTROL_SETUP), controlQueryContext::addSetupQuery, controlQueryContext::setException));
controlQueryResult = runMainQuery(controlQueryBundle.getQuery(), CONTROL, controlQueryContext);
controlQueryContext.setState(QueryState.SUCCEEDED);
} else {
controlQueryContext.setState(NOT_RUN);
}
// Run test queries
QueryBundle testQueryBundle = test.get();
QueryAction testSetupAction = setupOnMainClusters ? queryActions.getTestAction() : queryActions.getHelperAction();
testQueryBundle.getSetupQueries().forEach(query -> runAndConsume(() -> testSetupAction.execute(query, TEST_SETUP), testQueryContext::addSetupQuery, testQueryContext::setException));
testQueryResult = runMainQuery(testQueryBundle.getQuery(), TEST, testQueryContext);
testQueryContext.setState(QueryState.SUCCEEDED);
// Verify results
if (!skipControl && !skipChecksum) {
matchResult = Optional.of(verify(control.get(), test.get(), controlQueryResult, testQueryResult, controlChecksumQueryContext, testChecksumQueryContext));
// Determinism analysis
if (matchResult.get().isMismatchPossiblyCausedByNonDeterminism()) {
determinismAnalysisDetails = Optional.of(analyzeDeterminism(control.get(), matchResult.get()));
}
}
partialResult = Optional.of(concludeVerificationPartial(control, test, controlQueryContext, testQueryContext, matchResult, determinismAnalysisDetails, Optional.empty()));
} catch (Throwable t) {
if (exceptionClassifier.shouldResubmit(t) && verificationContext.getResubmissionCount() < verificationResubmissionLimit) {
return new VerificationResult(this, true, Optional.empty());
}
throwable = Optional.of(t);
partialResult = Optional.of(concludeVerificationPartial(control, test, controlQueryContext, testQueryContext, matchResult, determinismAnalysisDetails, Optional.of(t)));
} finally {
if (!smartTeardown || testQueryContext.getState() != QueryState.SUCCEEDED || (partialResult.isPresent() && partialResult.get().getStatus().equals(SUCCEEDED))) {
QueryAction controlTeardownAction = teardownOnMainClusters ? queryActions.getControlAction() : queryActions.getHelperAction();
QueryAction testTeardownAction = teardownOnMainClusters ? queryActions.getTestAction() : queryActions.getHelperAction();
teardownSafely(controlTeardownAction, control, controlQueryContext::addTeardownQuery);
teardownSafely(testTeardownAction, test, testQueryContext::addTeardownQuery);
}
}
return concludeVerification(partialResult.get(), control, test, controlQueryResult, testQueryResult, controlQueryContext, testQueryContext, matchResult, controlChecksumQueryContext, testChecksumQueryContext, determinismAnalysisDetails, throwable);
}
Aggregations