Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error handling during determinism analysis #15056

Merged
merged 1 commit into from
Aug 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import static com.facebook.presto.verifier.framework.DataVerificationUtil.getColumns;
import static com.facebook.presto.verifier.framework.DataVerificationUtil.match;
import static com.facebook.presto.verifier.framework.DataVerificationUtil.teardownSafely;
import static com.facebook.presto.verifier.framework.DeterminismAnalysis.ANALYSIS_FAILED;
import static com.facebook.presto.verifier.framework.DeterminismAnalysis.ANALYSIS_FAILED_DATA_CHANGED;
import static com.facebook.presto.verifier.framework.DeterminismAnalysis.ANALYSIS_FAILED_INCONSISTENT_SCHEMA;
import static com.facebook.presto.verifier.framework.DeterminismAnalysis.ANALYSIS_FAILED_QUERY_FAILURE;
Expand Down Expand Up @@ -98,11 +97,33 @@ protected DeterminismAnalysis analyze(QueryBundle control, ChecksumResult contro
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:
// try the next analysis
break;
case NON_DETERMINISTIC:
return NON_DETERMINISTIC_LIMIT_CLAUSE;
case DETERMINISTIC:
return DETERMINISTIC;
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.getTableName());
Map<QueryBundle, DeterminismAnalysisRun.Builder> queryRuns = new HashMap<>();

try {
// Rerun control query
for (int i = 0; i < maxAnalysisRuns; i++) {
QueryBundle queryBundle = queryRewriter.rewriteQuery(sourceQuery.getControlQuery(), CONTROL);
DeterminismAnalysisRun.Builder run = determinismAnalysisDetails.addRun().setTableName(queryBundle.getTableName().toString());
Expand All @@ -128,32 +149,11 @@ protected DeterminismAnalysis analyze(QueryBundle control, ChecksumResult contro
}
}

// Handle limit query
LimitQueryDeterminismAnalysis limitQueryAnalysis = new LimitQueryDeterminismAnalyzer(
prestoAction,
handleLimitQuery,
control.getQuery(),
controlChecksum.getRowCount(),
determinismAnalysisDetails).analyze();

switch (limitQueryAnalysis) {
case NON_DETERMINISTIC:
return NON_DETERMINISTIC_LIMIT_CLAUSE;
case NOT_RUN:
case DETERMINISTIC:
return DETERMINISTIC;
case FAILED_DATA_CHANGED:
return ANALYSIS_FAILED_DATA_CHANGED;
default:
throw new IllegalArgumentException(format("Invalid limitQueryAnalysis: %s", limitQueryAnalysis));
}
return DETERMINISTIC;
}
catch (QueryException qe) {
return ANALYSIS_FAILED_QUERY_FAILURE;
}
catch (Throwable t) {
return ANALYSIS_FAILED;
}
finally {
if (runTeardown) {
queryRuns.forEach((queryBundle, run) -> teardownSafely(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ public enum LimitQueryDeterminismAnalysis
NON_DETERMINISTIC,
DETERMINISTIC,
FAILED_DATA_CHANGED,
FAILED_QUERY_FAILURE,
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import static com.facebook.presto.sql.QueryUtil.simpleQuery;
import static com.facebook.presto.verifier.framework.LimitQueryDeterminismAnalysis.DETERMINISTIC;
import static com.facebook.presto.verifier.framework.LimitQueryDeterminismAnalysis.FAILED_DATA_CHANGED;
import static com.facebook.presto.verifier.framework.LimitQueryDeterminismAnalysis.FAILED_QUERY_FAILURE;
import static com.facebook.presto.verifier.framework.LimitQueryDeterminismAnalysis.NON_DETERMINISTIC;
import static com.facebook.presto.verifier.framework.LimitQueryDeterminismAnalysis.NOT_RUN;
import static com.facebook.presto.verifier.framework.QueryStage.DETERMINISM_ANALYSIS_MAIN;
Expand Down Expand Up @@ -89,7 +90,14 @@ public LimitQueryDeterminismAnalyzer(

public LimitQueryDeterminismAnalysis analyze()
{
LimitQueryDeterminismAnalysis analysis = analyzeInternal();
LimitQueryDeterminismAnalysis analysis;
try {
analysis = analyzeInternal();
}
catch (QueryException queryException) {
analysis = FAILED_QUERY_FAILURE;
}

determinismAnalysisDetails.setLimitQueryAnalysis(analysis);
return analysis;
}
Expand Down